﻿using System;
using System.Web;
using ZX.BLL.Extend;
using ZX.Web.UI.Controls;
using ZX.CRM.Library;
using ZX.Common;
using System.Collections;
using System.Collections.Generic;
using ZX.CRM.Bussiness;
using ZX.DAL.DBExtend;
using ZX.DBModule;
using System.Data.SqlClient;
using System.Data;
using ZX.BLL;
using ZX.EHR.Library;
using ZX.SYS.Bussiness.Message;
using ZX.SYS.Library;
using ZX.Common.Extend;

namespace ZX.WebApp.AjaxData
{
    public partial class CustomOperating : BasePage
    {
        BTCrmCustomer bll = new BTCrmCustomer();
        ZX.CRM.Web.CrmWorkFlowService.WorkFlowServiceClient workFlowServiceClient = new ZX.CRM.Web.CrmWorkFlowService.WorkFlowServiceClient();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.UserId == null)
            {
                Response.Write("因长时间不操作系统，用户相关信息失效，请退出重新登录！");
                return;
            }
            string strAction = this.GetStringFromQueryString("action", "");
            string strEntity = this.GetStringFromQueryString("entity", "E_Menu");
            string flag = this.GetStringFromQueryString("flag", "");
            string strType = this.GetStringFromQueryString("type", "");
            string strJson = "";
            if (flag == "1")
            {
                string Forms = ZXContext.Request.Form[0].ToString();
                strJson = Forms;
            }
            else
            {
                strJson = this.GetStringFromQueryString("json", "").Replace("[@@]", "\\");
            }
            if (strType == "1" && strEntity == "CrmCustomerAttach")
            {
                string id = this.GetStringFromQueryString("id", "");
                IList<V_CrmCustomerAttach> listAttach = bll.GetAllCrmCustomerAttachInfo(new Guid(id));
                if (listAttach != null && listAttach.Count > 0)
                {
                    IList<BaseEntity> _listAttach = new List<BaseEntity>();
                    foreach (var _e in listAttach)
                    {
                        _listAttach.Add(_e);
                    }
                    string strAttach = "[" + _listAttach.ToJSON().Replace("\n", "").Replace("\r", "").Replace("@@", "") + "]";
                    //ZX.Common.Globals.ObjectToJSON(listAttach);
                    HttpContext.Current.Response.Write(strAttach);
                }
                else
                {
                    IList<V_CrmCustomerAttach> listAttachInfo = bll.GetAllCrmCustomerInfoAttachInfo(new Guid(id));
                    if (listAttachInfo != null && listAttachInfo.Count > 0)
                    {
                        IList<BaseEntity> _listAttachInfo = new List<BaseEntity>();
                        foreach (var _e in listAttachInfo)
                        {
                            _listAttachInfo.Add(_e);
                        }
                        string strAttach = "[" + _listAttachInfo.ToJSON().Replace("\n", "").Replace("\r", "").Replace("@@", "") + "]";
                        HttpContext.Current.Response.Write(strAttach);
                    }
                }
                return;
            }
            switch (strAction)
            {
                case "delete":
                    RunDelete(strEntity, strJson);
                    break;
                case "procedure":
                    RunProcedure(strEntity, strJson, strAction);
                    break;
                case "check":
                    RunCheck(strEntity, strJson);
                    break;
                case "insert":
                    InsertIntoInfo(strEntity, strJson);
                    break;
                case "lenovo":
                    LoadCustomerName(strJson);
                    break;
                case "update":
                    RunUpdate(strEntity, strJson);
                    break;
                default:
                    break;

            }
        }
        /// <summary>
        /// 自定义删除方法
        /// </summary>
        /// <param name="strEntity"></param>
        /// <param name="strJson"></param>
        private void RunDelete(string strEntity, string strJson)
        {
            switch (strEntity)
            {
                case "CrmUserMove":
                    CrmUserMoveDelete(strJson);
                    break;
                case "CrmValue":
                    DeleteCrmValue(strJson);
                    break;
                case "CrmLinkMan":
                    DeleteCrmLinkMan(strJson);
                    break;
                case "CrmActivity":
                    DeleteCrmActivity(strJson);
                    break;
                case "CrmCustomerAttach":
                    DeleteCrmCustomerAttach(strJson);
                    break;
                case "CrmCustomer":
                case "CrmCustomerInfo":
                    SetCrmCustomerIsValue(strEntity, strJson);
                    break;
                case "CrmCustomerRelation":
                    DeleteCrmCustomerRelation(strJson);
                    break;
                case "CrmOrderProduct":
                    DeleteCrmOrderProduct(strJson);
                    break;
                case "CrmPackDetail":
                    DeleteCrmPackDetail(strJson);
                    break;
                case "CrmCustomerOrder":
                    DeleteCrmCustomerOrder(strJson);
                    break;
                case "CrmMajorStudent":
                    DeleteCrmMajorStudent(strJson);
                    break;
                case "CrmMajorStudentHr":
                    DeleteMajorStudentHr(strJson);
                    break;
                case "CrmDeliverMajor":
                    DeleteCrmDeliverMajor(strJson);
                    break;
                case "CrmCustomerStop":
                    DeleteCrmCustomerStop();
                    break;
                case "CrmInvoiceApplyProduct":
                    DeleteCrmInvoiceApplyProduct();
                    break;
                case "CrmCustomerChannel":
                    DeleteCrmCustomerChannel();
                    break;
                case "V_CrmPay":
                    DeleteCrmCustomerPay();
                    break;
                case "CrmLayoutRecord":
                    DeleteCrmLayoutRecord();
                    break;
                default:
                    break;
            }
        }
        /// <summary>
        /// 员工异动
        /// </summary>
        /// <param name="strJson"></param>
        private void CrmUserMoveDelete(string strJson)
        {
            strJson = this.GetStringFromQueryString("id", "");
            try
            {
                BaseBussnies bll = new BaseBussnies();
                string strSql = string.Format("update CrmUserMove set IsValue='0' where ID='{0}'", strJson);
                int iResult = bll.RunSqlCommand(strSql);
                if (iResult > 0)
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("0");
                }
            }
            catch
            {
                HttpContext.Current.Response.Write("0");
            }
        }
        /// <summary>
        /// 删除联系人
        /// </summary>
        /// <param name="strJson"></param>
        private void DeleteCrmLinkMan(string strJson)
        {
            strJson = this.GetStringFromQueryString("id", "");
            try
            {
                BaseBussnies bll = new BaseBussnies();
                string strSql = string.Format("delete CrmLinkMan where ID='{0}'", strJson);
                int iResult = bll.RunSqlCommand(strSql);
                if (iResult > 0)
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("0");
                }
            }
            catch
            {
                HttpContext.Current.Response.Write("0");
            }
        }
        /// <summary>
        /// 删除联系人
        /// </summary>
        /// <param name="strJson"></param>
        private void DeleteCrmValue(string strJson)
        {
            strJson = this.GetStringFromQueryString("id", "");
            try
            {
                int iresults = 0;
                IDataParameter[] _Parameters = new IDataParameter[] { };
                DbSql db = new DbSql();
                string strId = this.GetStringFromQueryString("id", "");
                IDataParameter[] Parameterss = new IDataParameter[] { };
                DbSql db1 = new DbSql();
                SqlParameter IDs = new SqlParameter("@ID", SqlDbType.UniqueIdentifier, 50);
                IDs.Direction = ParameterDirection.Input;
                IDs.Value = new Guid(strId);
                SqlParameter ReturnValues = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValues.Direction = ParameterDirection.Output;
                Parameterss = new IDataParameter[] { IDs, ReturnValues };
                string strReturnValues = db.RunProcedureReturnString("sp_DeleteCrmValue", Parameterss, out iresults);
                if (strReturnValues == "1")
                {
                    BaseBussnies bll = new BaseBussnies();
                    SysDataLog log = new SysDataLog();
                    log.UserID = this.User.UserID;
                    log.Action = "Delete";
                    log.Data = "IP:" + this.Request.UserHostAddress + ",LoginName:" + this.UserName;
                    log.EntityName = "CrmValue";
                    log.LogTime = DateTime.Now;
                    bll.entity = log;
                    bll.Insert();
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write(strReturnValues);
                }
            }
            catch
            {
                HttpContext.Current.Response.Write("0");
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="strJson"></param>
        private void DeleteCrmActivity(string strJson)
        {
            strJson = this.GetStringFromQueryString("id", "");
            try
            {
                BaseBussnies bll = new BaseBussnies();
                string strSql = string.Format("delete CrmActivity where ID='{0}'", strJson);
                int iResult = bll.RunSqlCommand(strSql);
                if (iResult > 0)
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("0");
                }
            }
            catch
            {
                HttpContext.Current.Response.Write("0");
            }
        }
        /// <summary>
        /// 删除附件
        /// </summary>
        /// <param name="strJson"></param>
        private void DeleteCrmCustomerAttach(string strJson)
        {
            strJson = this.GetStringFromQueryString("aid", "");
            string strCustomerId = this.GetStringFromQueryString("id", "");
            string ListId = this.GetStringFromQueryString("listId", "");
            string strListId = "";
            if (ListId != "")
            {
                strListId = ListId.Substring(0, ListId.Length - 1);
            }
            try
            {
                string strSql = string.Format("Exec sp_DelCrmCustomerAttach '{0}','{1}','{2}'",
                                            strJson, strCustomerId, strListId);
                int iResult = bll.RunSqlCommand(strSql);
                if (iResult > 0)
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("0");
                }
            }
            catch
            {
                HttpContext.Current.Response.Write("0");
            }
        }
        /// <summary>
        /// 停用客户
        /// </summary>
        /// <param name="strJson"></param>
        private void SetCrmCustomerIsValue(string strEntity, string strJson)
        {
            string strSql = "";
            #region oldStopMethod
            /*BaseBussnies blls = new BaseBussnies();
            strJson = this.GetStringFromQueryString("id", "");
            string type = this.GetStringFromQueryString("type", "");
            try
            {
                if (strEntity == "CrmCustomer")  //CrmCustomer停用客户
                {
                    if (bll.CheckCustomerIsPrevateState(new Guid(strJson)))
                    {
                        strSql = string.Format("update CrmCustomer set IsValue='{0}' where ID='{1}'", type, strJson);
                    }
                    else
                    {
                        //该客户已被处理，不是公海客户，请及时刷新数据!
                        HttpContext.Current.Response.Write("2");
                        return;
                    }
                }
                else if (strEntity == "CrmCustomerInfo")  //CrmCustomerInfo停用客户
                {
                    strSql = string.Format("update CrmCustomerInfo set IsValue='{0}' where ID='{1}'", type, strJson);
                }
                int iResult = blls.RunSqlCommand(strSql);
                if (iResult > 0)
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("0");
                }
            }
            catch
            {
                HttpContext.Current.Response.Write("0");
            }*/
            #endregion

            try
            {
                strJson = this.GetStringFromQueryString("id", "");
                int iResult = 0;
                IDataParameter[] _Parameters = new IDataParameter[] { };
                DbSql db = new DbSql();
                SqlParameter CustomerId = new SqlParameter("@CustomerId", SqlDbType.UniqueIdentifier, 50);
                CustomerId.Direction = ParameterDirection.Input;
                CustomerId.Value = new Guid(strJson);
                SqlParameter Type = new SqlParameter("@Type", SqlDbType.Int, 1);
                Type.Direction = ParameterDirection.Input;
                if (strEntity == "CrmCustomer")  //CrmCustomer停用客户
                {
                    Type.Value = 1;

                    if (!bll.GetCrmCustomerPublic(new Guid(strJson)))
                    {
                        HttpContext.Current.Response.Write("该客户不是公海客户，不能停用!");
                        return;
                    }
                }
                else if (strEntity == "CrmCustomerInfo")  //CrmCustomerInfo停用客户
                {
                    Type.Value = 2;
                }
                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;

                _Parameters = new IDataParameter[] { CustomerId, Type, ReturnValue };
                strSql = db.RunProcedureReturnString("sp_EditCrmCustomerStop", _Parameters, out iResult);
                if (strSql == "1")
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write(strSql);
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 删除客户关系信息
        /// </summary>
        /// <param name="RelationId"></param>
        private void DeleteCrmCustomerRelation(string RelationId)
        {
            try
            {
                RelationId = this.GetStringFromQueryString("id", "");
                BaseBussnies bll = new BaseBussnies();
                string strSql = string.Format("delete CrmCustomerRelation where ID='{0}'", RelationId);
                int iResult = bll.RunSqlCommand(strSql);
                if (iResult > 0)
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("0");
                }
            }
            catch
            {
                HttpContext.Current.Response.Write("0");
            }
        }
        /// <summary>
        /// 删除订单产品数据
        /// </summary>
        /// <param name="OrderProductId"></param>
        private void DeleteCrmOrderProduct(string strOrderProductId)
        {
            try
            {
                strOrderProductId = this.GetStringFromQueryString("id", "");
                string strOrderId = this.GetStringFromQueryString("oid", "");
                int iResult = 0;
                string strType = this.GetStringFromQueryString("type", "");
                if (strType == "order")
                {
                    BaseBussnies bll = new BaseBussnies();
                    string strSql = string.Format("delete CrmOrderProduct where OrderID='{0}'", strOrderId);
                    int iRows = bll.RunSqlCommand(strSql);
                    if (iRows > 0)
                    {
                        string strUpdate = string.Format("update CrmCustomerOrder set TotalMoney=0 where ID='{0}'", strOrderId);
                        int _iRows = bll.RunSqlCommand(strUpdate);
                        if (_iRows > 0)
                        {
                            HttpContext.Current.Response.Write("1");
                        }
                        else
                        {
                            HttpContext.Current.Response.Write("删除产品时更新订单中总金额失败!");
                        }
                    }
                    else
                    {
                        HttpContext.Current.Response.Write("删除产品失败!");
                    }
                }
                else
                {

                    IDataParameter[] _Parameters = new IDataParameter[] { };
                    DbSql db = new DbSql();
                    try
                    {
                        SqlParameter OrderProdcutId = new SqlParameter("@OrderProdcutId", SqlDbType.UniqueIdentifier, 50);
                        OrderProdcutId.Direction = ParameterDirection.Input;
                        OrderProdcutId.Value = new Guid(strOrderProductId);
                        SqlParameter OrderId = new SqlParameter("@OrderId", SqlDbType.UniqueIdentifier, 50);
                        OrderId.Direction = ParameterDirection.Input;
                        OrderId.Value = new Guid(strOrderId);
                        SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                        ReturnValue.Direction = ParameterDirection.Output;
                        _Parameters = new IDataParameter[] { OrderProdcutId, OrderId, ReturnValue };
                        string strSql = db.RunProcedureReturnString("sp_DeleteCrmOrderProduct", _Parameters, out iResult);
                        if (strSql == "1")
                        {
                            HttpContext.Current.Response.Write("1");
                        }
                        else
                        {
                            HttpContext.Current.Response.Write("0");
                        }
                    }
                    catch (Exception ex)
                    {
                        HttpContext.Current.Response.Write(ex);
                    }
                }
            }
            catch
            {
                HttpContext.Current.Response.Write("0");
            }
        }
        /// <summary>
        /// 删除产品包子数据
        /// </summary>
        /// <param name="PackDetailId"></param>
        private void DeleteCrmPackDetail(string strPackDetailId)
        {
            try
            {
                strPackDetailId = this.GetStringFromQueryString("id", "");
                string strPackId = this.GetStringFromQueryString("pid", "");
                int iResult = 0;
                IDataParameter[] _Parameters = new IDataParameter[] { };
                DbSql db = new DbSql();
                try
                {
                    SqlParameter PackDetailId = new SqlParameter("@PackDetailId", SqlDbType.UniqueIdentifier, 50);
                    PackDetailId.Direction = ParameterDirection.Input;
                    PackDetailId.Value = new Guid(strPackDetailId);
                    SqlParameter PackId = new SqlParameter("@PackId", SqlDbType.UniqueIdentifier, 50);
                    PackId.Direction = ParameterDirection.Input;
                    PackId.Value = new Guid(strPackId);
                    SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                    ReturnValue.Direction = ParameterDirection.Output;
                    _Parameters = new IDataParameter[] { PackDetailId, PackId, ReturnValue };
                    string strSql = db.RunProcedureReturnString("sp_DeleteCrmPackDetail", _Parameters, out iResult);
                    if (strSql == "1")
                    {
                        HttpContext.Current.Response.Write("1");
                    }
                    else
                    {
                        HttpContext.Current.Response.Write("0");
                    }
                }
                catch (Exception ex)
                {
                    HttpContext.Current.Response.Write(ex);
                }
            }
            catch
            {
                HttpContext.Current.Response.Write("0");
            }
        }
        /// <summary>
        /// 删除订单
        /// </summary>
        /// <param name="strOrderId"></param>
        private void DeleteCrmCustomerOrder(string strOrderType)
        {
            strOrderType = this.GetStringFromQueryString("type", "");
            string strOrderId = this.GetStringFromQueryString("id", "");
            int iResult = 0;
            IDataParameter[] _Parameters = new IDataParameter[] { };
            DbSql db = new DbSql();
            try
            {
                SqlParameter OrderType = new SqlParameter("@OrderType", SqlDbType.Int, 1);
                OrderType.Direction = ParameterDirection.Input;
                if (strOrderType == "0") //约场订单删除
                {
                    OrderType.Value = 0;
                }
                else   //销售订单删除
                {
                    OrderType.Value = 1;
                }
                SqlParameter OrderId = new SqlParameter("@OrderId", SqlDbType.UniqueIdentifier, 50);
                OrderId.Direction = ParameterDirection.Input;
                OrderId.Value = new Guid(strOrderId);
                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;

                _Parameters = new IDataParameter[] { OrderType, OrderId, ReturnValue };
                string strSql = db.RunProcedureReturnString("sp_DeleteCrmCustomerOrder", _Parameters, out iResult);
                if (strSql == "1")
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write(strSql);
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 删除公开课学员
        /// </summary>
        /// <param name="strMajorId"></param>
        private void DeleteCrmMajorStudent(string strMajorId)
        {
            try
            {
                strMajorId = this.GetStringFromQueryString("mid", ""); //公开课ID
                string strStudentId = this.GetStringFromQueryString("id", ""); //学员ID
                BaseBussnies bll = new BaseBussnies();
                string strSql = string.Format("delete CrmMajorStudent where ID='{0}'", strStudentId);
                int iResult = bll.RunSqlCommand(strSql);
                if (iResult > 0)
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("0");
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 删除英才学员
        /// </summary>
        /// <param name="strMajorId"></param>
        private void DeleteMajorStudentHr(string strMajorId)
        {
            try
            {
                string strStudentId = this.GetStringFromQueryString("id", ""); //学员ID
                BaseBussnies bll = new BaseBussnies();
                string strSql = string.Format("delete CrmMajorStudentHr where ID='{0}'", strStudentId);
                int iResult = bll.RunSqlCommand(strSql);
                if (iResult > 0)
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("0");
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 删除公开课
        /// </summary>
        /// <param name="strMajorId"></param>
        private void DeleteCrmDeliverMajor(string strMajorId)
        {
            try
            {
                strMajorId = this.GetStringFromQueryString("id", ""); //公开课ID
                int iResult = 0;
                IDataParameter[] _Parameters = new IDataParameter[] { };
                DbSql db = new DbSql();
                SqlParameter MajorId = new SqlParameter("@MajorId", SqlDbType.UniqueIdentifier, 50);
                MajorId.Direction = ParameterDirection.Input;
                MajorId.Value = new Guid(strMajorId);
                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;

                _Parameters = new IDataParameter[] { MajorId, ReturnValue };
                string strSql = db.RunProcedureReturnString("sp_DeleteCrmDeliverMajor", _Parameters, out iResult);
                if (strSql == "1")
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write(strSql);
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 删除停用客户
        /// </summary>
        private void DeleteCrmCustomerStop()
        {
            try
            {
                BaseBussnies blls = new BaseBussnies();
                string strCustomerId = this.GetStringFromQueryString("id", "");
                string strSql = string.Format("delete CrmCustomerStop where ID='{0}'", strCustomerId);
                int iResult = blls.RunSqlCommand(strSql);
                if (iResult > 0)
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("0");
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 删除发票申请产品信息
        /// </summary>
        private void DeleteCrmInvoiceApplyProduct()
        {
            try
            {
                BaseBussnies blls = new BaseBussnies();
                string strCondition = this.GetStringFromQueryString("condition", "");
                string strSql = string.Format("delete CrmInvoiceApplyProduct where " + strCondition + "");
                int iResult = blls.RunSqlCommand(strSql);
                if (iResult > 0)
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("0");
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 渠道客户最后一个节点
        /// </summary>
        private void DeleteCrmCustomerChannel()
        {
            try
            {
                int iResult = 0;
                IDataParameter[] _Parameters = new IDataParameter[] { };
                DbSql db = new DbSql();
                string strId = this.GetStringFromQueryString("id", "");
                string strType = this.GetStringFromQueryString("t","");
                if (strType == "1") //检查
                {
                    SqlParameter ZcustomerID = new SqlParameter("@ZcustomerID", SqlDbType.UniqueIdentifier, 50);
                    ZcustomerID.Direction = ParameterDirection.Input;
                    ZcustomerID.Value = new Guid(strId);
                    SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                    ReturnValue.Direction = ParameterDirection.Output;

                    _Parameters = new IDataParameter[] { ZcustomerID, ReturnValue };
                    string strReturnValue = db.RunProcedureReturnString("Sp_GetCrmCustomerIfRight", _Parameters, out iResult);
                    HttpContext.Current.Response.Write(strReturnValue);
                }
                else if (strType == "2")
                {
                    int iresults = 0;
                    IDataParameter[] Parameterss = new IDataParameter[] { };
                    DbSql db1 = new DbSql();
                    SqlParameter IDs = new SqlParameter("@ZcustomerID", SqlDbType.UniqueIdentifier, 50);
                    IDs.Direction = ParameterDirection.Input;
                    IDs.Value = new Guid(strId);
                    SqlParameter adduser = new SqlParameter("@adduser", SqlDbType.UniqueIdentifier, 50);
                    adduser.Direction = ParameterDirection.Input;
                    adduser.Value = new Guid(this.UserId.ToString());
                    SqlParameter ReturnValues = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                    ReturnValues.Direction = ParameterDirection.Output;
                    Parameterss = new IDataParameter[] { IDs, adduser, ReturnValues };
                    string strReturnValues = db.RunProcedureReturnString("Sp_AddCrmCustomerIfRight", Parameterss, out iresults);
                    if (strReturnValues == "1")
                    {
                        string strOperatorInstanceId = this.GetStringFromQueryString("OperatorInstanceId", "");
                        string msg1 = workFlowServiceClient.Run(this.User.LoginName, strOperatorInstanceId, "提交");
                        HttpContext.Current.Response.Write("1");
                    }
                    else
                    {
                        HttpContext.Current.Response.Write(strReturnValues);
                    }
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 删除期初数据
        /// </summary>
        private void DeleteCrmLayoutRecord()
        {
            try
            {
                int iResult = 0;
                IDataParameter[] _Parameters = new IDataParameter[] { };
                DbSql db = new DbSql();
                string strRecordId = this.GetStringFromQueryString("rid", "");
                string strRecordProdcutId = this.GetStringFromQueryString("id", "");
                SqlParameter RecordId = new SqlParameter("@RecordId", SqlDbType.UniqueIdentifier, 50);
                RecordId.Direction = ParameterDirection.Input;
                RecordId.Value = new Guid(strRecordId);
                SqlParameter RecordProductId = new SqlParameter("@RecordProductId", SqlDbType.UniqueIdentifier, 50);
                RecordProductId.Direction = ParameterDirection.Input;
                RecordProductId.Value = new Guid(strRecordProdcutId);
                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;

                _Parameters = new IDataParameter[] { RecordId, RecordProductId, ReturnValue };
                string strReturnValue = db.RunProcedureReturnString("sp_DeleteCrmLayoutRecord", _Parameters, out iResult);
                if (strReturnValue == "1")
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write(strReturnValue);
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 删除缴款单信息
        /// </summary>
        private void DeleteCrmCustomerPay()
        {
            try
            {
                int iresults = 0;
                IDataParameter[] _Parameters = new IDataParameter[] { };
                DbSql db = new DbSql();
                string strId = this.GetStringFromQueryString("id", "");               
                IDataParameter[] Parameterss = new IDataParameter[] { };
                DbSql db1 = new DbSql();
                SqlParameter IDs = new SqlParameter("@PayId", SqlDbType.UniqueIdentifier, 50);
                IDs.Direction = ParameterDirection.Input;
                IDs.Value = new Guid(strId);
                SqlParameter adduser = new SqlParameter("@UserId", SqlDbType.UniqueIdentifier, 50);
                adduser.Direction = ParameterDirection.Input;
                adduser.Value = new Guid(this.UserId.ToString());
                SqlParameter ReturnValues = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValues.Direction = ParameterDirection.Output;
                Parameterss = new IDataParameter[] { IDs, adduser, ReturnValues };
                string strReturnValues = db.RunProcedureReturnString("sp_DeleteCrmPay", Parameterss, out iresults);
                if (strReturnValues == "1")
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write(strReturnValues);
                }
                
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }

        /// <summary>
        /// 自定义修改方法
        /// </summary>
        /// <param name="strEntity"></param>
        /// <param name="strJson"></param>
        private void RunUpdate(string strEntity, string strJson)
        {
            switch (strEntity)
            {
                case "CrmCustomer":
                    ModifyCrmCustomerAddUserId(strJson);
                    break;
                case "CrmCustomerOrderField":
                    ModifyCrmCustomerOrder(strJson);
                    break;
                case "CrmPay":
                    ModifyCrmCustomerPay(strJson);
                    break;
                case "CrmCustomerInfo":
                    ModifyCrmCustomerDistribution(strJson);
                    break;
                case "CrmCustomerOrder":
                    ModifyCustomerOrderCheckState(strJson);
                    break;
                case "CrmCustomerOrderF":
                case "CrmCustomerOrderS":
                    ModifyCustomerOrderInfo(strEntity, strJson);
                    break;
                case "AddCrmCustomerReturn":
                    AddCrmCustomerReturn(strJson);
                    break;
                case "CrmCustomerReturn":
                    UpdateCrmCustomerReturn(strJson);
                    break;
                case "CrmDeliverMajor":
                    UpdateCrmDeliverMajorInfo(strJson);
                    break;
                case "CrmDeliverMajors":
                    UpdateCrmDeliverMajors(strJson);
                    break;
                case "CrmDeliverMajorProject":
                    UpdateCrmDeliverMajorProject(strJson);
                    break;
                case "CrmDeliverScb":
                    UpdateCrmDeliverScb(strJson);
                    break;
                case "CrmDeliverSsr":
                    UpdateCrmDeliverSsr(strJson);
                    break;
                case "CrmDeliverHxfw":
                    UpdateCrmDeliverHxfw(strJson);
                    break;
                case "CrmDeliverTrain":
                    UpdateCrmDeliverTrain(strJson);
                    break;
                case "CrmDeliverHr":
                    UpdateCrmDeliverHr(strJson);
                    break;
                case "CrmDeliverTrainScb":
                    UpdateCrmDeliverTrainScb(strJson);
                    break;
                case "CrmDeliverHrZgsh":
                    UpdateCrmDeliverHrZgsh(strJson);
                    break;
                case "CrmDeliverTrainSsr":
                    UpdateCrmDeliverTrainSsr(strJson);
                    break;
                case "CrmDeliverHrSsr":
                    UpdateCrmDeliverHrSsr(strJson);
                    break;
                case "CustomerUpdate":
                    UpdateCustomerProduce(strJson);
                    break;
                case "CustomerInfoUpdate":
                    UpdateCustomerInfoProduce(strJson);
                    break;
                case "CrmMajorStudent_G":
                    UpdateCrmMajorStudentGroup(strJson);
                    break;
                case "CrmCustomeToCustomerInfo":
                    UpdateCrmCustomeToCustomerInfo();
                    break;
                case "CrmProductLayoutRole":
                    UpdateCrmProductLayoutRole(strJson);
                    return;
                case "CrmCustomerOld":
                    UpdateCrmCustomerOld();
                    break;
                case "CrmCustomerOldd":
                    UpdateCrmCustomerOldd();
                    break;
                case "CrmStudentSign":
                    UpdateCrmStudentGroupNameAndGroupNumber();
                    break;
                case "bpm_OpenClassBudgetMaster":
                    UpdateBudgetMasteAccount();
                    break;
                case "MajorStudentGroupName":
                    UpdateMajorStudentGroupName();
                    break;
                case "CrmCustomerOldUpdate":
                    UpdateCrmCustomerOldUpdate(strJson);
                    break;
                case "ToCrmCustomerOld":
                    UpdateToCrmCustomerOld();
                    break;
                case "SetNegotiateTeach":
                    UpdateSetNegotiateTeach(strJson);
                    break;
                case "CrmCustomerOldStop":
                    UpdateCrmCustomerOldStop();
                    break;
                case "CrmCustomerStop":
                    UpdateCrmCustomerStop();
                    break;
                case "CrmCommisionInfo":
                    UpdateCrmCommisionInfo(strJson);
                    break;
                case "CrmCommision":
                    string OrderProductId = this.GetStringFromQueryString("OrderProductId", "");
                    string UserId = this.GetStringFromQueryString("UserId", "");
                    string CommissionTime = this.GetStringFromQueryString("CommissionTime", "");
                    SaveCommision(OrderProductId, UserId, CommissionTime, "Sp_GetCrmComisionByOrder");
                    break;
                case "CrmProductPayValue_yitui":
                    string OPId = this.GetStringFromQueryString("OrderProductId", "");
                    string UId = this.GetStringFromQueryString("UserId", "");
                    string CTime = this.GetStringFromQueryString("CommissionTime", "");
                    SaveCommision(OPId, UId, CTime, "Sp_GetCrmComisionExtend");
                    break;
                case "V_CrmProductPayValue_yitui":
                    UpdateCrmCommisionInfo_Yitui(strJson);
                    break;
                case "V_CrmProductPayValue_Check":
                    UpdateCrmCommisionInfo_Check(strJson);
                    break;
                case "CrmCommisionExtend":
                    UpdateCrmCommisionInfo_Check(strJson);
                    break;
                default:
                    break;
            }
        }
        /// <summary>
        /// 计算佣金基础表
        /// </summary>
        /// <param name="Commision">佣金所属月份</param>
        private void SaveCommision(string orderproductid, string userid, string Commisiondate,string procName)
        {
            BCrmPayFlow cr = new BCrmPayFlow();
            Guid UserId = new Guid(userid.ToString());
            string returnstr = cr.ExecCrmCommisionInfo(orderproductid, UserId, Convert.ToDateTime(Commisiondate),procName);

            if (returnstr.Trim().Length < 1)
                HttpContext.Current.Response.Write("1");
            else
                HttpContext.Current.Response.Write(returnstr);


        }
        /// <summary>
        /// 确认取消佣金
        /// </summary>
        /// <param name="strJson"></param>
        private void UpdateCrmCommisionInfo(string strJson)
        {
            strJson = this.GetStringFromQueryString("id", "");  //客户ID
            try
            {
                string strSql = string.Format("Exec sp_EditCommissionInfo '{0}','{1}','{2}'", strJson, this.UserId.ToString(),this.GetStringFromQueryString("type",""));
                int iResult = bll.RunSqlCommand(strSql);
                if (iResult > 0)
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("操作失败!");
                }

            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 一推确认佣金业绩
        /// </summary>
        /// <param name="strJson"></param>
        private void UpdateCrmCommisionInfo_Check(string strJson)
        {
            strJson = this.GetStringFromQueryString("id", "");  //客户ID
            try
            {
                string strSql = string.Format("Exec sp_EditCrmCommisionExtend '{0}','{1}','{2}'", strJson, this.UserId.ToString(), this.GetStringFromQueryString("type", ""));
                int iResult = bll.RunSqlCommand(strSql);
                if (iResult > 0)
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("操作失败!");
                }

            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 一推确认取消佣金
        /// </summary>
        /// <param name="strJson"></param>
        private void UpdateCrmCommisionInfo_Yitui(string strJson)
        {
            strJson = this.GetStringFromQueryString("id", "");  //客户ID
            try
            {
                string strSql = string.Format("Exec sp_EditCrmCommisionCheck '{0}','{1}','{2}'", strJson, this.UserId.ToString(), this.GetStringFromQueryString("type", ""));
                int iResult = bll.RunSqlCommand(strSql);
                if (iResult > 0)
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("操作失败!");
                }

            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 一推确认取消佣金_成交场
        /// </summary>
        /// <param name="strJson"></param>
        private void UpdateCrmCommisionInfo_YituiBargain(string strJson)
        {
            try
            {
                string strId = this.GetStringFromQueryString("id", "");
                string strCustomerCode = IDMaker.GetSequenceStr("CUS001");

                int iResult = 0;
                IDataParameter[] _Parameters = new IDataParameter[] { };
                DbSql db = new DbSql();
                SqlParameter Attachdate = new SqlParameter("@Attachdate", SqlDbType.DateTime, 50);
                Attachdate.Direction = ParameterDirection.Input;
                Attachdate.Value = Convert.ToDateTime(strId);
                
                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;
                _Parameters = new IDataParameter[] { Attachdate, ReturnValue };
                string strSql = db.RunProcedureReturnString("Sp_GetCrmComisionExtend_Bargain", _Parameters, out iResult);
                if (strSql == "1")
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write(strSql);
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }



        /// <summary>
        /// 修改信息专员
        /// </summary>
        /// <param name="strJson"></param>
        private void ModifyCrmCustomerAddUserId(string strJson)
        {
            strJson = this.GetStringFromQueryString("id", "");  //客户ID
            try
            {
                if (bll.GetCrmCustomerPublic(new Guid(strJson)))
                {
                    string strId = this.GetStringFromQueryString("userid", ""); //专员ID
                    string strSql = string.Format("Exec sp_UpdateCrmCustomerUserId '{0}','{1}','{2}'", strJson, strId, this.UserId);
                    int iResult = bll.RunSqlCommand(strSql);
                    if (iResult > 0)
                    {
                        HttpContext.Current.Response.Write("1");
                    }
                    else
                    {
                        HttpContext.Current.Response.Write("修改失败!");
                    }
                }
                else
                {
                    HttpContext.Current.Response.Write("该客户已被处理，不是公海客户，请及时刷新数据!");
                    return;
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 订单变更
        /// </summary>
        /// <param name="strJson"></param>
        private void ModifyCrmCustomerOrder(string strJson)
        {
            strJson = this.GetStringFromQueryString("oid", "");//订单ID
            string strCustomerId = this.GetStringFromQueryString("cid", "");//客户ID
            string strName = this.GetStringFromQueryString("name", "");//订单名称
            string strOrderStateId = this.GetStringFromQueryString("sid", "");//订单状态ID
            try
            {
                string strSql = string.Format("Exec sp_EditCrmCustomerOrder '{0}','{1}','{2}','{3}','{4}','{5}'",
                                        strJson, strCustomerId, strOrderStateId, this.UserId, DateTime.Now, strName);
                int iResult = bll.RunSqlCommand(strSql);
                if (iResult > 0)
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("修改失败!");
                }
            }
            catch
            {
                HttpContext.Current.Response.Write("修改失败!");
            }
        }
        /// <summary>
        /// 修改订单信息--新建状态下修改
        /// </summary>
        /// <param name="strEntity"></param>
        /// <param name="strJson"></param>
        private void ModifyCustomerOrderInfo(string strEntity, string strJson)
        {
            int iResult = 0;
            IDataParameter[] _Parameters = new IDataParameter[] { };
            DbSql db = new DbSql();
            try
            {
                CrmCustomerOrder instance = (CrmCustomerOrder)Globals.JSonToObject<CrmCustomerOrder>(strJson);
                Globals.SetPropertyValue(instance, "AddUser", this.UserId);
                Globals.SetPropertyValue(instance, "AddTime", System.DateTime.Now);

                SqlParameter ID = new SqlParameter("@ID", SqlDbType.UniqueIdentifier, 50);
                ID.Direction = ParameterDirection.Input;
                ID.Value = instance.ID;
                SqlParameter Code = new SqlParameter("@Code", SqlDbType.Char, 50);
                Code.Direction = ParameterDirection.Input;
                Code.Value = instance.Code;
                SqlParameter CustomerId = new SqlParameter("@CustomerId", SqlDbType.UniqueIdentifier, 50);
                CustomerId.Direction = ParameterDirection.Input;
                CustomerId.Value = instance.CustomerId;
                SqlParameter DeptId = new SqlParameter("@DeptId", SqlDbType.UniqueIdentifier, 50);
                DeptId.Direction = ParameterDirection.Input;
                DeptId.Value = instance.DeptId;
                SqlParameter Date = new SqlParameter("@Date", SqlDbType.DateTime, 50);
                Date.Direction = ParameterDirection.Input;
                Date.Value = instance.Date;
                SqlParameter TypeID = new SqlParameter("@TypeID", SqlDbType.UniqueIdentifier, 50);
                TypeID.Direction = ParameterDirection.Input;
                TypeID.Value = instance.TypeID;
                SqlParameter ValutaID = new SqlParameter("@ValutaID", SqlDbType.UniqueIdentifier, 50);
                ValutaID.Direction = ParameterDirection.Input;
                ValutaID.Value = instance.ValutaID;
                SqlParameter PillID = new SqlParameter("@PillID", SqlDbType.UniqueIdentifier, 50);
                PillID.Direction = ParameterDirection.Input;
                PillID.Value = instance.PillID;
                SqlParameter CourseLoyoutID = new SqlParameter("@CourseLoyoutID", SqlDbType.UniqueIdentifier, 50);
                CourseLoyoutID.Direction = ParameterDirection.Input;
                CourseLoyoutID.Value = instance.CourseLoyoutID;
                SqlParameter PaymentId = new SqlParameter("@PaymentId", SqlDbType.UniqueIdentifier, 50);
                PaymentId.Direction = ParameterDirection.Input;
                PaymentId.Value = instance.PaymentId;
                SqlParameter Explain = new SqlParameter("@Explain", SqlDbType.NVarChar, 1000);
                Explain.Direction = ParameterDirection.Input;
                Explain.Value = instance.Explain;
                SqlParameter AddUser = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
                AddUser.Direction = ParameterDirection.Input;
                AddUser.Value = instance.AddUser;
                SqlParameter AddTime = new SqlParameter("@AddTime", SqlDbType.DateTime, 50);
                AddTime.Direction = ParameterDirection.Input;
                AddTime.Value = instance.AddTime;
                SqlParameter TotalMoney = new SqlParameter("@TotalMoney", SqlDbType.Decimal, 20);
                TotalMoney.Direction = ParameterDirection.Input;
                TotalMoney.Value = instance.TotalMoney;
                SqlParameter StateID = new SqlParameter("@StateID", SqlDbType.UniqueIdentifier, 50);
                StateID.Direction = ParameterDirection.Input;
                StateID.Value = instance.StateID;

                SqlParameter ProductPackID = new SqlParameter("@ProductPackID", SqlDbType.UniqueIdentifier, 50);
                ProductPackID.Direction = ParameterDirection.Input;
                ProductPackID.Value = instance.ProductPackID;
                SqlParameter IsPerformance = new SqlParameter("@IsPerformance", SqlDbType.Char, 1);
                IsPerformance.Direction = ParameterDirection.Input;
                IsPerformance.Value = instance.IsPerformance;

                SqlParameter ProduectList = new SqlParameter("@ProduectList", SqlDbType.NVarChar, 4000);
                ProduectList.Direction = ParameterDirection.Input;
                ProduectList.Value = instance.ProduectList;
                SqlParameter CustomerZjList = new SqlParameter("@CustomerZjList", SqlDbType.NVarChar, 4000);
                CustomerZjList.Direction = ParameterDirection.Input;
                CustomerZjList.Value = instance.CustomerZjList;
                SqlParameter CustomerServerList = new SqlParameter("@CustomerServerList", SqlDbType.NVarChar, 4000);
                CustomerServerList.Direction = ParameterDirection.Input;
                CustomerServerList.Value = instance.CustomerServerList;

                SqlParameter TeacherId = new SqlParameter("@TeacherId", SqlDbType.UniqueIdentifier, 50);
                TeacherId.Direction = ParameterDirection.Input;
                TeacherId.Value = instance.TeacherId;
                SqlParameter TeacherTime = new SqlParameter("@TeacherTime", SqlDbType.DateTime, 50);
                TeacherTime.Direction = ParameterDirection.Input;
                TeacherTime.Value = instance.TeacherTime;
                SqlParameter TeacherAddress = new SqlParameter("@TeacherAddress", SqlDbType.NVarChar, 40);
                TeacherAddress.Direction = ParameterDirection.Input;
                TeacherAddress.Value = instance.TeacherAddress;
                SqlParameter TeacherType = new SqlParameter("@TeacherType", SqlDbType.NVarChar, 50);
                TeacherType.Direction = ParameterDirection.Input;
                TeacherType.Value = instance.TeacherType;

                SqlParameter LinkManId = new SqlParameter("@LinkManId", SqlDbType.UniqueIdentifier, 50);
                LinkManId.Direction = ParameterDirection.Input;
                LinkManId.Value = instance.LinkManId;
                SqlParameter LinkManCode = new SqlParameter("@LinkManCode", SqlDbType.NVarChar, 15);
                LinkManCode.Direction = ParameterDirection.Input;
                LinkManCode.Value = ZX.BLL.IDMaker.GetSequenceStr("CUS002");
                SqlParameter LinkManName = new SqlParameter("@LinkManName", SqlDbType.NVarChar, 30);
                LinkManName.Direction = ParameterDirection.Input;
                LinkManName.Value = instance.LinkManName;
                SqlParameter LinkManSex = new SqlParameter("@LinkManSex", SqlDbType.NVarChar, 1);
                LinkManSex.Direction = ParameterDirection.Input;
                LinkManSex.Value = instance.LinkManSex;
                SqlParameter LinkManPosition = new SqlParameter("@LinkManPosition", SqlDbType.NVarChar, 20);
                LinkManPosition.Direction = ParameterDirection.Input;
                LinkManPosition.Value = instance.LinkManPosition;
                SqlParameter LinkManTel = new SqlParameter("@LinkManTel", SqlDbType.NVarChar, 20);
                LinkManTel.Direction = ParameterDirection.Input;
                LinkManTel.Value = instance.LinkManTel;

                SqlParameter ZhuYueRenID = new SqlParameter("@ZhuYueRenID", SqlDbType.UniqueIdentifier, 50);
                ZhuYueRenID.Direction = ParameterDirection.Input;
                ZhuYueRenID.Value = instance.ZhuYueRenID;

                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;

                SqlParameter WorkFlowId = new SqlParameter("@WorkFlowId", SqlDbType.NVarChar, 50);
                WorkFlowId.Direction = ParameterDirection.Input;
                WorkFlowId.Value = instance.WorkFlowId;
                SqlParameter WorkTaskId = new SqlParameter("@WorkTaskId", SqlDbType.NVarChar, 50);
                WorkTaskId.Direction = ParameterDirection.Input;
                WorkTaskId.Value = instance.WorkTaskId;
                SqlParameter WorkFlowInsId = new SqlParameter("@WorkFlowInsId", SqlDbType.NVarChar, 50);
                WorkFlowInsId.Direction = ParameterDirection.Input;
                WorkFlowInsId.Value = instance.WorkFlowInsId;
                SqlParameter WorkTaskInsId = new SqlParameter("@WorkTaskInsId", SqlDbType.NVarChar, 50);
                WorkTaskInsId.Direction = ParameterDirection.Input;
                WorkTaskInsId.Value = instance.WorkTaskInsId;
                SqlParameter CheckUser = new SqlParameter("@CheckUser", SqlDbType.NVarChar, 50);
                CheckUser.Direction = ParameterDirection.Input;
                CheckUser.Value = instance.CheckUser;
                SqlParameter EXP1 = new SqlParameter("@EXP1", SqlDbType.NVarChar, 40);
                EXP1.Direction = ParameterDirection.Input;
                EXP1.Value = instance.EXP1;

                SqlParameter PresentationType = new SqlParameter("@PresentationType", SqlDbType.UniqueIdentifier, 50);
                PresentationType.Direction = ParameterDirection.Input;
                PresentationType.Value = instance.PresentationType;
                SqlParameter PresentationOrderId = new SqlParameter("@PresentationOrderId", SqlDbType.UniqueIdentifier, 50);
                PresentationOrderId.Direction = ParameterDirection.Input;
                PresentationOrderId.Value = instance.PresentationOrderId;
                SqlParameter PresentationReason = new SqlParameter("@PresentationReason", SqlDbType.NVarChar, 1000);
                PresentationReason.Direction = ParameterDirection.Input;
                PresentationReason.Value = instance.PresentationReason;

                SqlParameter IsHistory = new SqlParameter("@IsHistory", SqlDbType.Char, 1);
                IsHistory.Direction = ParameterDirection.Input;
                IsHistory.Value = instance.IsHistory;

                SqlParameter OrderType = new SqlParameter("@OrderType", SqlDbType.Int, 1);
                OrderType.Direction = ParameterDirection.Input;

                SqlParameter HistoryIsModifyState = new SqlParameter("@HistoryIsModifyState", SqlDbType.Int, 1);
                HistoryIsModifyState.Direction = ParameterDirection.Input;


                string strDesc = this.GetStringFromQueryString("desc", "");
                string strOperatorInstanceId = this.GetStringFromQueryString("OperatorInstanceId", "");
                if (strDesc == "lsdd")
                {
                    HistoryIsModifyState.Value = 1;
                }
                else
                {
                    HistoryIsModifyState.Value = 0;
                }

                if (strEntity == "CrmCustomerOrderF")  //约场订单
                {
                    OrderType.Value = 0;
                }
                else if (strEntity == "CrmCustomerOrderS")  //其它类型订单
                {
                    OrderType.Value = 1;
                }
                _Parameters = new IDataParameter[] { ID, Code, CustomerId, DeptId, Date, TypeID, ValutaID, 
                        PillID, CourseLoyoutID, PaymentId, Explain, AddUser, AddTime, TotalMoney, StateID, OrderType,
                        EXP1, ProduectList, CustomerZjList, CustomerServerList, TeacherId, TeacherTime, TeacherAddress,
                        TeacherType, LinkManId, LinkManCode, LinkManName, LinkManSex, LinkManPosition, LinkManTel, ZhuYueRenID,
                        ProductPackID, IsPerformance, CheckUser, PresentationType, PresentationOrderId, PresentationReason, 
                        IsHistory, HistoryIsModifyState, ReturnValue };
                string strSql = db.RunProcedureReturnString("sp_UpdateCrmCustomerOrder", _Parameters, out iResult);
                if (strSql == "1")
                {
                    if (strDesc == "lsdd")
                    {
                        string msgClaim = workFlowServiceClient.TaskClaim(this.User.LoginName, strOperatorInstanceId);
                        string msgRun = workFlowServiceClient.Run(this.User.LoginName, strOperatorInstanceId, "提交");
                        HttpContext.Current.Response.Write("1");
                        return;
                    }
                    HttpContext.Current.Response.Write("1");
                }
                else if (strSql == "2")
                {
                    HttpContext.Current.Response.Write("该讲师在当前时间段已安排讲场!");
                }
                else
                {
                    HttpContext.Current.Response.Write(strSql);
                }
            }
            catch(Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 缴款单变更
        /// </summary>
        /// <param name="strJson"></param>
        private void ModifyCrmCustomerPay(string strJson)
        {
            try
            {
                int iResult = 0;
                IDataParameter[] _Parameters = new IDataParameter[] { };
                DbSql db = new DbSql();
                CrmPay instance = (CrmPay)Globals.JSonToObject<CrmPay>(strJson);
                SqlParameter ID = new SqlParameter("@ID", SqlDbType.UniqueIdentifier, 50);
                ID.Direction = ParameterDirection.Input;
                ID.Value = instance.ID;
                SqlParameter DeptId = new SqlParameter("@DeptId", SqlDbType.UniqueIdentifier, 50);
                DeptId.Direction = ParameterDirection.Input;
                DeptId.Value = instance.DeptId;
                SqlParameter Receipt = new SqlParameter("@Receipt", SqlDbType.NVarChar, 50);
                Receipt.Direction = ParameterDirection.Input;
                Receipt.Value = instance.Receipt;
                SqlParameter ValutaID = new SqlParameter("@ValutaID", SqlDbType.UniqueIdentifier, 50);
                ValutaID.Direction = ParameterDirection.Input;
                ValutaID.Value = instance.ValutaID;
                SqlParameter PillID = new SqlParameter("@PillID", SqlDbType.UniqueIdentifier, 50);
                PillID.Direction = ParameterDirection.Input;
                PillID.Value = instance.PillID;
                SqlParameter InvoiceNum = new SqlParameter("@InvoiceNum", SqlDbType.NVarChar, 50);
                InvoiceNum.Direction = ParameterDirection.Input;
                InvoiceNum.Value = instance.@InvoiceNum;
                SqlParameter Explain = new SqlParameter("@Explain", SqlDbType.NVarChar, 1000);
                Explain.Direction = ParameterDirection.Input;
                Explain.Value = instance.Explain;
                SqlParameter EXP1 = new SqlParameter("@EXP1", SqlDbType.NVarChar, 50);
                EXP1.Direction = ParameterDirection.Input;
                EXP1.Value = instance.EXP1;
                SqlParameter EXP2 = new SqlParameter("@EXP2", SqlDbType.NVarChar, 50);
                EXP2.Direction = ParameterDirection.Input;
                EXP2.Value = instance.EXP2;
                SqlParameter EXP3 = new SqlParameter("@EXP3", SqlDbType.NVarChar, 50);
                EXP3.Direction = ParameterDirection.Input;
                EXP3.Value = instance.EXP3;
                SqlParameter EXP4 = new SqlParameter("@EXP4", SqlDbType.NVarChar, 50);
                EXP4.Direction = ParameterDirection.Input;
                EXP4.Value = instance.EXP4;
                SqlParameter PayDate = new SqlParameter("@PayDate", SqlDbType.DateTime, 50);
                PayDate.Direction = ParameterDirection.Input;
                PayDate.Value = instance.PayDate;
                SqlParameter FactPayDate = new SqlParameter("@FactPayDate", SqlDbType.DateTime, 50);
                FactPayDate.Direction = ParameterDirection.Input;
                FactPayDate.Value = instance.FactPayDate;
                SqlParameter StateID = new SqlParameter("@State", SqlDbType.UniqueIdentifier, 50);
                StateID.Direction = ParameterDirection.Input;
                StateID.Value = instance.State;
                SqlParameter ProduectList = new SqlParameter("@ProduectList", SqlDbType.NVarChar, 4000);
                ProduectList.Direction = ParameterDirection.Input;
                ProduectList.Value = instance.ProduectList;                      //@Adduser
                SqlParameter Adduser = new SqlParameter("@Adduser", SqlDbType.UniqueIdentifier, 50);
                Adduser.Direction = ParameterDirection.Input;
                Adduser.Value = this.UserId;
                SqlParameter CZName = new SqlParameter("@CZName", SqlDbType.UniqueIdentifier, 50);
                CZName.Direction = ParameterDirection.Input;
                CZName.Value = instance.CZName;
                SqlParameter FZName = new SqlParameter("@FZName", SqlDbType.UniqueIdentifier, 50);
                FZName.Direction = ParameterDirection.Input;
                FZName.Value = instance.FZName;
                SqlParameter CTeam = new SqlParameter("@CTeam", SqlDbType.UniqueIdentifier, 50);
                CTeam.Direction = ParameterDirection.Input;
                CTeam.Value = instance.CTeam;
                SqlParameter CJName = new SqlParameter("@CJName", SqlDbType.UniqueIdentifier, 50);
                CJName.Direction = ParameterDirection.Input;
                CJName.Value = instance.CJName;
                SqlParameter PayAddress = new SqlParameter("@PayAddress", SqlDbType.NVarChar, 50);
                PayAddress.Direction = ParameterDirection.Input;
                PayAddress.Value = instance.PayAddress;               
                SqlParameter BankDate = new SqlParameter("@BankDate", SqlDbType.DateTime, 50);
                BankDate.Direction = ParameterDirection.Input;
                BankDate.Value = instance.BankDate;
                SqlParameter AccountFrom = new SqlParameter("@AccountFrom", SqlDbType.UniqueIdentifier, 50);
                AccountFrom.Direction = ParameterDirection.Input;
                AccountFrom.Value = instance.AccountFrom;
               
                SqlParameter IsYj = new SqlParameter("@IsYj", SqlDbType.NVarChar, 4000);
                IsYj.Direction = ParameterDirection.Input;
                IsYj.Value = instance.IsYj;
                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;
                string strSql = "";
                string strSaveType = this.GetStringFromQueryString("saveType", "");
                if (strSaveType == "direct")
                {
                    _Parameters = new IDataParameter[] { ID, ValutaID, DeptId,PillID,InvoiceNum,Receipt,PayDate, FactPayDate,   
                           Explain,EXP1,EXP2,EXP3, ProduectList,Adduser,CZName, FZName, CTeam, CJName,BankDate,AccountFrom,PayAddress, IsYj, ReturnValue};
                    strSql = db.RunProcedureReturnString("sp_EditCrmDirectPay", _Parameters, out iResult);
                    if (strSql == "1")
                    {
                        HttpContext.Current.Response.Write("1");
                    }
                    else
                    {
                        HttpContext.Current.Response.Write("直接保存数据失败!");
                    }
                }
                else
                {
                    _Parameters = new IDataParameter[] { ID, ValutaID, DeptId, PillID, InvoiceNum, StateID, Explain, EXP1, CZName, FZName, CTeam, CJName,PayAddress, ReturnValue };

                    strSql = db.RunProcedureReturnString("sp_EditCrmCustomerPay", _Parameters, out iResult);
                    if (strSql == "1")
                    {
                        HttpContext.Current.Response.Write("1");
                    }
                    else
                    {
                        HttpContext.Current.Response.Write("保存数据失败!");
                    }
                }
            }
            catch
            {
                HttpContext.Current.Response.Write("修改失败!");
            }
        }
        /// <summary>
        /// 客户分配
        /// </summary>
        /// <param name="CustomerIds"></param>
        private void ModifyCrmCustomerDistribution(string CustomerIds)
        {
            CustomerIds = this.GetStringFromQueryString("id", "");  //客户ID
            string strUserId = this.GetStringFromQueryString("uid", "");  //分配的用户ID
            string[] strIds = CustomerIds.Split(',');
            try
            {
                for (int i = 0; i < strIds.Length - 1; i++)
                {

                    string strReturn = this.ReturnSaveMsg("客户分配", "【分配客户】" + GetCustomerName(strIds[i] == "" ? Guid.Empty : new Guid(strIds[i]), 0) + "!", this.UserId.ToString() == "" ? Guid.Empty : new Guid(this.UserId.ToString()), strUserId == "" ? Guid.Empty : new Guid(strUserId));
                       
                    string strSql = string.Format("Exec sp_AddCrmCustomerDistribution '{0}','{1}','{2}'",
                                    strIds[i], strUserId, this.UserId);
                    int iResult = bll.RunSqlCommand(strSql);
                    if (iResult > 0)
                    {
                    }
                    else
                    {
                        HttpContext.Current.Response.Write("0");
                        return;
                    }
                }
                HttpContext.Current.Response.Write("1");
            }
            catch
            {
                HttpContext.Current.Response.Write("0");
            }
        }
        /// <summary>
        /// 订单审核
        /// </summary>
        /// <param name="strJson"></param>
        private void ModifyCustomerOrderCheckState(string strJson)
        {
            strJson = this.GetStringFromQueryString("id", "");  //订单ID
            string strCheckId = this.UserId.ToString();
            try
            {
                BTCrmCrustomerOrder bllOrder = new BTCrmCrustomerOrder();
                V_CrmCustomerOrder Orders = bllOrder.GetAllCrmCustomerOrder(new Guid(strJson));
                if (Orders.StateID.ToString() == "319FDCFA-3948-495B-88B0-1EAB7DC9F138")
                {
                    HttpContext.Current.Response.Write("您当前的订单处于 签核中 状态，无须审核!");
                    return;
                }
                else if (Orders.StateID.ToString() == "af73673f-9fec-4d14-acfd-b0fce08d6ffa")
                {
                    HttpContext.Current.Response.Write("您当前的订单处于 待交付 状态，无须审核!");
                    return;
                }
                else if (Orders.StateID.ToString() == "eda4faa9-8544-494c-bf1c-02662e1078a6")
                {
                    HttpContext.Current.Response.Write("您当前的订单处于 交付中 状态，无须审核!");
                    return;
                }
                else if (Orders.StateID.ToString() == "bddcaf31-98d4-423a-9275-9288f85e2847")
                {
                    HttpContext.Current.Response.Write("您当前的订单处于 结案 状态，无须审核!");
                    return;
                }
                else if (Orders.StateID.ToString() == "c2af1c1f-6937-40ee-8d40-2e6203e34119")
                {
                    HttpContext.Current.Response.Write("您当前的订单处于 报废 状态，无须审核!");
                    return;
                }
                else
                {
                    BaseBussnies blls = new BaseBussnies();
                    string strSql = string.Format("update CrmCustomerOrder set StateID='{0}', CheckID='{1}',CheckTime='{2}' where ID='{3}'",
                                                    "af73673f-9fec-4d14-acfd-b0fce08d6ffa", strCheckId, DateTime.Now.ToString(), strJson);
                    int iResult = blls.RunSqlCommand(strSql);
                    if (iResult > 0)
                    {
                        HttpContext.Current.Response.Write("1");
                    }
                    else
                    {
                        HttpContext.Current.Response.Write("审核失败!");
                    }
                }
            }
            catch
            {
                HttpContext.Current.Response.Write("审核失败!");
            }
        }
        /// <summary>
        /// 公海客户退回
        /// </summary>
        private void AddCrmCustomerReturn(string strJson)
        { 
            try
            {
                int iResult = 0;
                IDataParameter[] _Parameters = new IDataParameter[] { };
                DbSql db = new DbSql();

                CrmCustomerReturn instance = Globals.JSonToObject<CrmCustomerReturn>(strJson);
                Globals.SetPropertyValue(instance, "AddUser", this.UserId);
                Globals.SetPropertyValue(instance, "AddTime", System.DateTime.Now);
                Globals.SetPropertyValue(instance, "ModifyUser", "00000000-0000-0000-0000-000000000000");
                Globals.SetPropertyValue(instance, "ModifyTime", "1900-01-01");

                SqlParameter CustomerId = new SqlParameter("@CustomerId", SqlDbType.UniqueIdentifier, 50);
                CustomerId.Direction = ParameterDirection.Input;
                CustomerId.Value = instance.CustomerId;
                SqlParameter ReciveUser = new SqlParameter("@ReciveUser", SqlDbType.UniqueIdentifier, 50);
                ReciveUser.Direction = ParameterDirection.Input;
                ReciveUser.Value = instance.ReciveUser;
                SqlParameter CustomerState = new SqlParameter("@CustomerState", SqlDbType.Int, 1);
                CustomerState.Direction = ParameterDirection.Input;
                CustomerState.Value = instance.CustomerState;
                SqlParameter ReturnReason = new SqlParameter("@ReturnReason", SqlDbType.NVarChar, 300);
                ReturnReason.Direction = ParameterDirection.Input;
                ReturnReason.Value = instance.ReturnReason;
                SqlParameter AddUser = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
                AddUser.Direction = ParameterDirection.Input;
                AddUser.Value = instance.AddUser;
                SqlParameter AddTime = new SqlParameter("@AddTime", SqlDbType.DateTime, 50);
                AddTime.Direction = ParameterDirection.Input;
                AddTime.Value = instance.AddTime;
                SqlParameter ModifyUser = new SqlParameter("@ModifyUser", SqlDbType.UniqueIdentifier, 50);
                ModifyUser.Direction = ParameterDirection.Input;
                ModifyUser.Value = instance.ModifyUser;
                SqlParameter ModifyTime = new SqlParameter("@ModifyTime", SqlDbType.DateTime, 50);
                ModifyTime.Direction = ParameterDirection.Input;
                ModifyTime.Value = instance.ModifyTime;

                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;

                _Parameters = new IDataParameter[] { CustomerId, ReciveUser, CustomerState, ReturnReason, AddUser, AddTime, ModifyUser, ModifyTime, ReturnValue };
                string strSql = db.RunProcedureReturnString("sp_AddCrmCustomerReturn", _Parameters, out iResult);
                if (strSql == "1")
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write(strSql);
                }
            }
            catch(Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 客户退回时修改退回列表信息
        /// </summary>
        /// <param name="strJson"></param>
        private void UpdateCrmCustomerReturn(string strJson)
        {
            try
            {
                strJson = this.GetStringFromQueryString("id", "");  //退回列表ID

                int iResult = 0;
                IDataParameter[] _Parameters = new IDataParameter[] { };
                DbSql db = new DbSql();

                SqlParameter CustomerReturnId = new SqlParameter("@CustomerReturnId", SqlDbType.UniqueIdentifier, 50);
                CustomerReturnId.Direction = ParameterDirection.Input;
                CustomerReturnId.Value = new Guid(strJson);
                SqlParameter AddUserId = new SqlParameter("@AddUserId", SqlDbType.UniqueIdentifier, 50);
                AddUserId.Direction = ParameterDirection.Input;
                AddUserId.Value = new Guid(this.UserId.ToString());
                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;

                _Parameters = new IDataParameter[] { CustomerReturnId, AddUserId, ReturnValue };
                string strSql = db.RunProcedureReturnString("sp_UpdateCrmCustomerReturn", _Parameters, out iResult);
                if (strSql == "1")
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write(strSql);
                }

                /*BaseBussnies bll = new BaseBussnies();
                string strSql = string.Format("update CrmCustomerReturn set CustomerState={0},ModifyUser='{1}',ModifyTime='{2}' where ID='{3}'",
                                               1, this.UserId, DateTime.Now, strJson);
                int iResult = bll.RunSqlCommand(strSql);
                if (iResult > 0)
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("0");
                }*/
            }
            catch(Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 更新大课信息
        /// </summary>
        /// <param name="strJson"></param>
        private void UpdateCrmDeliverMajorInfo(string strJson)
        {
            int iResult = 0;
            IDataParameter[] _Parameters = new IDataParameter[] { };
            DbSql db = new DbSql();
            try
            {
                CrmDeliverMajor instance = (CrmDeliverMajor)Globals.JSonToObject<CrmDeliverMajor>(strJson);
                Globals.SetPropertyValue(instance, "AddUser", this.UserId);
                Globals.SetPropertyValue(instance, "AddTime", System.DateTime.Now);

                SqlParameter ID = new SqlParameter("@ID", SqlDbType.UniqueIdentifier, 50);
                ID.Direction = ParameterDirection.Input;
                ID.Value = instance.ID;
                SqlParameter Code = new SqlParameter("@Code", SqlDbType.Char, 15);
                Code.Direction = ParameterDirection.Input;
                Code.Value = instance.Code;
                SqlParameter OrderProductID = new SqlParameter("@OrderProductID", SqlDbType.UniqueIdentifier, 50);
                OrderProductID.Direction = ParameterDirection.Input;
                OrderProductID.Value = instance.OrderProductID;
                SqlParameter ProductLayoutID = new SqlParameter("@ProductLayoutID", SqlDbType.UniqueIdentifier, 50);
                ProductLayoutID.Direction = ParameterDirection.Input;
                ProductLayoutID.Value = instance.ProductLayoutID;
                SqlParameter NegotiateTeach = new SqlParameter("@NegotiateTeach", SqlDbType.UniqueIdentifier, 50);
                NegotiateTeach.Direction = ParameterDirection.Input;
                NegotiateTeach.Value = instance.NegotiateTeach;
                SqlParameter ClassServer = new SqlParameter("@ClassServer", SqlDbType.UniqueIdentifier, 50);
                ClassServer.Direction = ParameterDirection.Input;
                ClassServer.Value = instance.ClassServer;
                SqlParameter ClassFrontServer = new SqlParameter("@ClassFrontServer", SqlDbType.UniqueIdentifier, 50);
                ClassFrontServer.Direction = ParameterDirection.Input;
                ClassFrontServer.Value = instance.ClassFrontServer;
                SqlParameter DliverState = new SqlParameter("@DliverState", SqlDbType.UniqueIdentifier, 50);
                DliverState.Direction = ParameterDirection.Input;
                DliverState.Value = instance.DliverState;
                SqlParameter AddUser = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
                AddUser.Direction = ParameterDirection.Input;
                AddUser.Value = instance.AddUser;
                SqlParameter AddTime = new SqlParameter("@AddTime", SqlDbType.DateTime, 50);
                AddTime.Direction = ParameterDirection.Input;
                AddTime.Value = instance.AddTime;
                SqlParameter StudentList = new SqlParameter("@StudentList", SqlDbType.NVarChar, 4000);
                StudentList.Direction = ParameterDirection.Input;
                StudentList.Value = instance.StudentList;

                SqlParameter GradeDeptId = new SqlParameter("@GradeDeptId", SqlDbType.UniqueIdentifier, 50);
                GradeDeptId.Direction = ParameterDirection.Input;
                GradeDeptId.Value = instance.GradeDeptId;
                SqlParameter ConstDeptId = new SqlParameter("@ConstDeptId", SqlDbType.UniqueIdentifier, 50);
                ConstDeptId.Direction = ParameterDirection.Input;
                ConstDeptId.Value = instance.ConstDeptId;
                SqlParameter exp3 = new SqlParameter("@exp3", SqlDbType.NVarChar, 50);
                exp3.Direction = ParameterDirection.Input;
                exp3.Value = instance.exp3;

                SqlParameter WorkFlowId = new SqlParameter("@WorkFlowId", SqlDbType.NVarChar, 50);
                WorkFlowId.Direction = ParameterDirection.Input;
                WorkFlowId.Value = instance.WorkFlowId;
                SqlParameter WorkTaskId = new SqlParameter("@WorkTaskId", SqlDbType.NVarChar, 50);
                WorkTaskId.Direction = ParameterDirection.Input;
                WorkTaskId.Value = instance.WorkTaskId;
                SqlParameter WorkFlowInsId = new SqlParameter("@WorkFlowInsId", SqlDbType.NVarChar, 50);
                WorkFlowInsId.Direction = ParameterDirection.Input;
                WorkFlowInsId.Value = instance.WorkFlowInsId;
                SqlParameter WorkTaskInsId = new SqlParameter("@WorkTaskInsId", SqlDbType.NVarChar, 50);
                WorkTaskInsId.Direction = ParameterDirection.Input;
                WorkTaskInsId.Value = instance.WorkTaskInsId;

                SqlParameter CustomerMgr = new SqlParameter("@CustomerMgr", SqlDbType.UniqueIdentifier, 50);
                CustomerMgr.Direction = ParameterDirection.Input;
                CustomerMgr.Value = instance.CustomerMgr;
                SqlParameter CustomerDirector = new SqlParameter("@CustomerDirector", SqlDbType.UniqueIdentifier, 50);
                CustomerDirector.Direction = ParameterDirection.Input;
                CustomerDirector.Value = instance.CustomerDirector;
                SqlParameter CustomerManager = new SqlParameter("@CustomerManager", SqlDbType.UniqueIdentifier, 50);
                CustomerManager.Direction = ParameterDirection.Input;
                CustomerManager.Value = instance.CustomerManager;


                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;

                _Parameters = new IDataParameter[] { ID,Code,OrderProductID,ProductLayoutID,NegotiateTeach,
					                        ClassServer,ClassFrontServer,DliverState,GradeDeptId,ConstDeptId,
                                            exp3,AddUser,AddTime, StudentList,
                                            WorkFlowId,WorkTaskId,WorkFlowInsId,WorkTaskInsId,
                                            CustomerMgr,CustomerDirector,CustomerManager,ReturnValue};
                string strSql = db.RunProcedureReturnString("sp_UpdateCrmDeliverMajor", _Parameters, out iResult);

                if (strSql == "1")
                {
                    if (instance.WorkTaskId != "")
                    {
                        string strView = this.GetStringFromQueryString("view", "");
                        if (strView == "m") //变更时重新提交流程
                        {
                            string userId = this.User.LoginName;

                            string msgClaim = workFlowServiceClient.TaskClaim(this.User.LoginName, strJson);
                            string msgRun = workFlowServiceClient.Start(userId, WorkFlowId.Value.ToString(), WorkTaskId.Value.ToString(),
                                 WorkFlowInsId.Value.ToString(), WorkTaskInsId.Value.ToString(), workFlowServiceClient.GetWorkFlowNO(), "提交", "3", GetStringFromQueryString("cName", "") + "─公开课交付申请单", false);
                            HttpContext.Current.Response.Write("1");
                        }
                        else if (strView == "c" || strView == "state")
                        {
                            HttpContext.Current.Response.Write("2"); //变更成功不走流程
                        }
                        else
                        {
                            string strOperatorInstanceId = this.GetStringFromQueryString("oid", ""); //流程操作ID
                            string msg1 = workFlowServiceClient.Run(this.User.LoginName, strOperatorInstanceId, "提交");
                            HttpContext.Current.Response.Write("1");

                        }
                    }
                    else
                    {
                        HttpContext.Current.Response.Write("2");
                    }
                }
                else
                {
                    HttpContext.Current.Response.Write(strSql);
                }
            }
            catch
            {
                HttpContext.Current.Response.Write("数据异常!保存失败!");
            }
        }
        /// <summary>
        /// 大课-更新产品规划
        /// </summary>
        /// <param name="strJson"></param>
        private void UpdateCrmDeliverMajors(string strJson)
        {
            strJson = this.GetStringFromQueryString("id", "");//大课ID
            string ProductLayoutId = this.GetStringFromQueryString("pid", ""); //产品规划ID
            string strOperatorInstanceId = this.GetStringFromQueryString("oid", ""); //流程操作ID
            string strWorkTaskInsId = this.GetStringFromQueryString("tid", ""); //流程任务ID
            string strAddUser = this.GetStringFromQueryString("adduser", ""); //添加人(确认人)
            string strAddTime = this.GetStringFromQueryString("addtime", "");//添加时间(确认时间)
            string strIsSure = "0";
            string strOrderId = this.GetStringFromQueryString("orderId", ""); //订单ID
            if (strAddUser != "00000000-0000-0000-0000-000000000000")
            {
                strIsSure = "1";
            }
            try
            {
                string strSql = string.Format("Exec sp_UpdateCrmDeliverMajorInfo '{0}','{1}','{2}','{3}','{4}','{5}'",
                                            strJson, ProductLayoutId, strIsSure, strAddUser, strAddTime, strOrderId);
                //string strSql = string.Format("update CrmDeliverMajor set ProductLayoutID='" + ProductLayoutId + "'," +
                //                     "IsSure='" + strIsSure + "',SureUser='" + strAddUser + "',SureTime='" + strAddTime + "' where ID='" + strJson + "'");
                int iResult = bll.RunSqlCommand(strSql);
                if (iResult > 0)
                {
                    string msg1 = workFlowServiceClient.Run(this.User.LoginName, strOperatorInstanceId, "提交");
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("0");
                }

                /*if (iResult > 0)
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("0");
                }*/
            }
            catch
            {
                HttpContext.Current.Response.Write("0");
            }
        }
        /// <summary>
        /// 项目-后续服务
        /// </summary>
        /// <param name="strJson"></param>
        private void UpdateCrmDeliverHxfw(string strJson)
        {
            strJson = this.GetStringFromQueryString("id", "");//大课ID

            string ServiceName = this.GetStringFromQueryString("ServiceName", "");//服务人员
            string ServiceDate = this.GetStringFromQueryString("ServiceDate", "") == "" ? "1900-01-01" : this.GetStringFromQueryString("ServiceDate", "");//时间
            string AdvisorIsAt = this.GetStringFromQueryString("AdvisorIsAt", "");//顾问是否到场
            string ServiceSatisfy = this.GetStringFromQueryString("ServiceSatisfy", "");//客户是否满意
            string strOperatorInstanceId = this.GetStringFromQueryString("oid", ""); //流程操作ID
            string strWorkTaskInsId = this.GetStringFromQueryString("tid", ""); //流程任务ID
            string strOrderProduct = GetStringFromQueryString("strOrderProduct", "");
            string DliverState = GetStringFromQueryString("DliverState", "");
            //string orderid = this.GetStringFromQueryString("orderid", "");
            try
            {
                SqlParameter OrderProductId = new SqlParameter("@OrderProductId", SqlDbType.UniqueIdentifier, 50);
                OrderProductId.Direction = ParameterDirection.Input;
                OrderProductId.Value = strOrderProduct == "" ? Guid.Empty : new Guid(strOrderProduct);
                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;
                string strSql = string.Format("update CrmDeliverMajorProject set ServiceSatisfy=" + ServiceSatisfy + " ,DliverState='" + DliverState + "',ServiceName='" + ServiceName + "',ServiceDate='" + ServiceDate + "', AdvisorIsAt=" + AdvisorIsAt + " where ID='" + strJson + "'");
                int iResult = bll.RunSqlCommand(strSql);
                int outNum = 0;
                IDataParameter[] _ParametersPro = new IDataParameter[] { };
                DbSql db = new DbSql();
                _ParametersPro = new IDataParameter[] { OrderProductId, ReturnValue };
                strSql = db.RunProcedureReturnString("sp_EditCrmDeliverProjectState", _ParametersPro, out outNum);
                if (iResult > 0)
                {
                    string msg1 = workFlowServiceClient.Run(this.User.LoginName, strOperatorInstanceId, "提交");
                    HttpContext.Current.Response.Write("1");
                }
            }
            catch
            {
                HttpContext.Current.Response.Write("0");
            }
        }
        /// <summary>
        /// 项目-更新实施团队
        /// </summary>
        /// <param name="strJson"></param>
        private void UpdateCrmDeliverSsr(string strJson)
        {
            strJson = this.GetStringFromQueryString("id", "");//大课ID
            string DateSum = this.GetStringFromQueryString("DateSum", ""); //项目天数
            string EndDate = this.GetStringFromQueryString("EndDate", "") == "" ? "1900-01-01" : this.GetStringFromQueryString("EndDate", "");//结束日期
            string PauseDate = this.GetStringFromQueryString("ProejectPauseDate", "") == "" ? "1900-01-01" : this.GetStringFromQueryString("ProejectPauseDate", "");//项目暂停日期
            string ReStartDate = this.GetStringFromQueryString("ProjectRestartDate", "") == "" ? "1900-01-01" : this.GetStringFromQueryString("ProjectRestartDate", "");//项目重启日期
            string leaveDate = this.GetStringFromQueryString("leaveDate", "") == "" ? "1900-01-01" : this.GetStringFromQueryString("leaveDate", "");//离项日期
            string SsExplain = this.GetStringFromQueryString("SsExplain", "");//备注
            string SsUser = this.GetStringFromQueryString("SsUser", "");//添加用户
            string SsDate = this.GetStringFromQueryString("SsDate", "") == "" ? "1900-01-01" : this.GetStringFromQueryString("SsDate", "");

            string strOperatorInstanceId = this.GetStringFromQueryString("oid", ""); //流程操作ID
            string strWorkTaskInsId = this.GetStringFromQueryString("tid", ""); //流程任务ID

            try
            {

                string strSql = string.Format("update CrmDeliverMajorProject set DateSum=" + DateSum + " ,LeaveProjectDate='" + leaveDate + "',ProejectPauseDate='" + PauseDate + "', ProjectRestartDate='" + ReStartDate + "', EndDate='" + EndDate + "', SsExplain='" + SsExplain + "',SsUser='" + SsUser + "',SsDate='" + SsDate + "' where ID='" + strJson + "'");
                int iResult = bll.RunSqlCommand(strSql);

                if (iResult > 0)
                {
                    string msg1 = workFlowServiceClient.Run(this.User.LoginName, strOperatorInstanceId, "提交");
                    HttpContext.Current.Response.Write("1");
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 项目-更新
        /// </summary>
        /// <param name="strJson"></param>
        private void UpdateCrmDeliverMajorProject(string strJson)
        {
            strJson = this.GetStringFromQueryString("id", "");//大课ID
            string PM = this.GetStringFromQueryString("PM", ""); //项目经理ID
            string BeginDate = this.GetStringFromQueryString("BeginDate", "") == "" ? "1900-01-01" : this.GetStringFromQueryString("BeginDate", "");//启动日期
            string PMemember = this.GetStringFromQueryString("PMemember", "");//项目成员
            string PExplain = this.GetStringFromQueryString("PExplain", "");//备注
            string ProjectUser = this.GetStringFromQueryString("ProjectUser", "");//添加用户
            string ProjectDate = this.GetStringFromQueryString("ProjectDate", "") == "" ? "1900-01-01" : this.GetStringFromQueryString("ProjectDate", "");
            string strOperatorInstanceId = this.GetStringFromQueryString("oid", ""); //流程操作ID
            string strWorkTaskInsId = this.GetStringFromQueryString("tid", ""); //流程任务ID
            string orderid = this.GetStringFromQueryString("orderid", "");
            string productid = this.GetStringFromQueryString("productid", "");
            string stateId = this.GetStringFromQueryString("stateId", "");
            string strView = this.GetStringFromQueryString("view", "");
            try
            {
                string strSql = "";
                //if (strView != "1")
                //{
                //    strSql = string.Format("update CrmDeliverMajorProject set DliverState='" + stateId + "' ,  PM='" + PM + "' ,BeginDate='" + BeginDate + "',PMemember='" + PMemember + "', PExplain='" + PExplain + "' where ID='" + strJson + "'");
                //}
                //else
                //{
                strSql = string.Format("update CrmDeliverMajorProject set DliverState='" + stateId + "' ,  PM='" + PM + "' ,BeginDate='" + BeginDate + "',PMemember='" + PMemember + "', PExplain='" + PExplain + "',ProjectUser='" + ProjectUser + "',ProjectDate='" + ProjectDate + "' where ID='" + strJson + "'");
                //}
                int iResult = bll.RunSqlCommand(strSql);
                if (iResult > 0)
                {
                    bll.RunSqlCommand("update CrmCustomerOrder set StateID='eda4faa9-8544-494c-bf1c-02662e1078a6' where ID='" + orderid + "'");
                    bll.RunSqlCommand("update CrmOrderProduct set StateId='EDA4FAA9-8544-494C-BF1C-02662E1078A6' where OrderID='" + orderid + "' and ProductId='" + productid + "'");
                    string msg1 = workFlowServiceClient.Run(this.User.LoginName, strOperatorInstanceId, "提交");
                    HttpContext.Current.Response.Write("1");
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 项目-更新市场部
        /// </summary>
        /// <param name="strJson"></param>
        private void UpdateCrmDeliverScb(string strJson)
        {
            strJson = this.GetStringFromQueryString("id", "");//大课ID

            string WellDegree = this.GetStringFromQueryString("WellDegree", "");//满意度
            string UnSatisfy = this.GetStringFromQueryString("UnSatisfy", "");//退款比例
            string Explain = this.GetStringFromQueryString("Explain", "");//备注
            string DegreeUser = this.GetStringFromQueryString("DegreeUser", "");//添加用户
            string DegreeDate = this.GetStringFromQueryString("DegreeDate", "");
            string strOperatorInstanceId = this.GetStringFromQueryString("oid", ""); //流程操作ID
            string strWorkTaskInsId = this.GetStringFromQueryString("tid", ""); //流程任务ID
            try
            {
                string strSql = string.Format("update CrmDeliverMajorProject set UnSatisfy=" + UnSatisfy + ",WellDegree=" + WellDegree + ", Explain='" + Explain + "',DegreeUser='" + DegreeUser + "',DegreeDate='" + DegreeDate + "' where ID='" + strJson + "'");
                int iResult = bll.RunSqlCommand(strSql);

                if (iResult > 0)
                {
                    string msg1 = workFlowServiceClient.Run(this.User.LoginName, strOperatorInstanceId, "提交");
                    HttpContext.Current.Response.Write("1");
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 内训-更新实施团队
        /// </summary>
        /// <param name="strJson"></param>
        private void UpdateCrmDeliverTrainSsr(string strJson)
        {
            strJson = this.GetStringFromQueryString("id", "");//大课ID
            string DateSum = this.GetStringFromQueryString("DateSum", ""); //项目天数
            string EndDate = this.GetStringFromQueryString("EndDate", "");//结束日期
            string ProduectList = this.GetStringFromQueryString("ProduectList", "");//备注
            string SsUser = this.GetStringFromQueryString("SsUser", "");//添加用户
            string SsDate = this.GetStringFromQueryString("SsDate", "");
            string strOperatorInstanceId = this.GetStringFromQueryString("oid", ""); //流程操作ID
            string strWorkTaskInsId = this.GetStringFromQueryString("tid", ""); //流程任务ID
            string strOrderProduct = GetStringFromQueryString("strOrderProduct", "");
            string DliverStates = GetStringFromQueryString("DliverState", "");
            try
            {
                SqlParameter OrderProductId = new SqlParameter("@OrderProductId", SqlDbType.UniqueIdentifier, 50);
                OrderProductId.Direction = ParameterDirection.Input;
                OrderProductId.Value = strOrderProduct == "" ? Guid.Empty : new Guid(strOrderProduct);

                int iResult = 0;
                IDataParameter[] _TrainParameters = new IDataParameter[] { };
                IDataParameter[] _Parameters1 = new IDataParameter[] { };
                DbSql db = new DbSql();

                SqlParameter spID = new SqlParameter("@ID", SqlDbType.UniqueIdentifier, 50);
                spID.Direction = ParameterDirection.Input;
                spID.Value = new Guid(strJson);
                SqlParameter spSsUser = new SqlParameter("@SsUser", SqlDbType.UniqueIdentifier, 50);
                spSsUser.Direction = ParameterDirection.Input;
                spSsUser.Value = new Guid(SsUser);
                SqlParameter DliverState = new SqlParameter("@DliverState", SqlDbType.UniqueIdentifier, 50);
                DliverState.Direction = ParameterDirection.Input;
                DliverState.Value = DliverStates == "" ? Guid.Empty : new Guid(DliverStates);
                SqlParameter spSsDate = new SqlParameter("@SsDate", SqlDbType.DateTime, 50);
                spSsDate.Direction = ParameterDirection.Input;
                spSsDate.Value = Convert.ToDateTime(SsDate);

                SqlParameter spEndDate = new SqlParameter("@EndDate", SqlDbType.DateTime, 50);
                spEndDate.Direction = ParameterDirection.Input;
                spEndDate.Value = Convert.ToDateTime(EndDate);

                SqlParameter spDateSum = new SqlParameter("@DateSum", SqlDbType.Decimal, 12);
                spDateSum.Direction = ParameterDirection.Input;
                spDateSum.Value = Convert.ToDecimal(DateSum);

                SqlParameter spProduectList = new SqlParameter("@ProduectList", SqlDbType.NVarChar, 4000);
                spProduectList.Direction = ParameterDirection.Input;
                spProduectList.Value = ProduectList;

                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;
                SqlParameter ReturnValue1 = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue1.Direction = ParameterDirection.Output;
                _Parameters1 = new IDataParameter[] { OrderProductId, ReturnValue };
                db.RunProcedureReturnString("sp_EditCrmDeliverTrainState", _Parameters1, out iResult);
                _TrainParameters = new IDataParameter[] {spDateSum,spID,DliverState ,spSsUser,spSsDate,spEndDate,   
                        spProduectList, ReturnValue1};

                string strSql = db.RunProcedureReturnString("sp_AddCrmTeacher", _TrainParameters, out iResult);

                if (strSql == "1")
                {
                    string msg1 = workFlowServiceClient.Run(this.User.LoginName, strOperatorInstanceId, "提交");
                    HttpContext.Current.Response.Write("1");
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 英才学校-更新结课
        /// </summary>
        /// <param name="strJson"></param>
        private void UpdateCrmDeliverHrSsr(string strJson)
        {
            strJson = this.GetStringFromQueryString("id", "");//大课ID
            string DateSum = this.GetStringFromQueryString("DateSum", ""); //项目天数
            string EndDate = this.GetStringFromQueryString("EndDate", "");//结束日期
            // string ProduectList = this.GetStringFromQueryString("ProduectList", "");//备注
            string SsUser = this.GetStringFromQueryString("SsUser", "");//添加用户
            string SsDate = this.GetStringFromQueryString("SsDate", "");
            string strOperatorInstanceId = this.GetStringFromQueryString("oid", ""); //流程操作ID
            string strWorkTaskInsId = this.GetStringFromQueryString("tid", ""); //流程任务ID
            string strOrderProduct = GetStringFromQueryString("strOrderProduct", "");
            string DliverStates = GetStringFromQueryString("DliverState", "");
            try
            {
                SqlParameter OrderProductId = new SqlParameter("@OrderProductId", SqlDbType.UniqueIdentifier, 50);
                OrderProductId.Direction = ParameterDirection.Input;
                OrderProductId.Value = strOrderProduct == "" ? Guid.Empty : new Guid(strOrderProduct);

                int iResult = 0;
                //IDataParameter[] _TrainParameters = new IDataParameter[] { };
                IDataParameter[] _Parameters1 = new IDataParameter[] { };
                DbSql db = new DbSql();

                SqlParameter spID = new SqlParameter("@ID", SqlDbType.UniqueIdentifier, 50);
                spID.Direction = ParameterDirection.Input;
                spID.Value = new Guid(strJson);
                SqlParameter spSsUser = new SqlParameter("@SsUser", SqlDbType.UniqueIdentifier, 50);
                spSsUser.Direction = ParameterDirection.Input;
                spSsUser.Value = new Guid(SsUser);
                SqlParameter DliverState = new SqlParameter("@DliverState", SqlDbType.UniqueIdentifier, 50);
                DliverState.Direction = ParameterDirection.Input;
                DliverState.Value = DliverStates == "" ? Guid.Empty : new Guid(DliverStates);
                SqlParameter spSsDate = new SqlParameter("@SsDate", SqlDbType.DateTime, 50);
                spSsDate.Direction = ParameterDirection.Input;
                spSsDate.Value = Convert.ToDateTime(SsDate);

                SqlParameter spEndDate = new SqlParameter("@EndDate", SqlDbType.DateTime, 50);
                spEndDate.Direction = ParameterDirection.Input;
                spEndDate.Value = Convert.ToDateTime(EndDate);

                SqlParameter spDateSum = new SqlParameter("@DateSum", SqlDbType.Decimal, 12);
                spDateSum.Direction = ParameterDirection.Input;
                spDateSum.Value = Convert.ToInt32(DateSum);

                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;
                SqlParameter ReturnValue1 = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue1.Direction = ParameterDirection.Output;
                _Parameters1 = new IDataParameter[] { spDateSum, spID, DliverState, spSsUser, spSsDate, spEndDate, OrderProductId, ReturnValue };
                string strSql = db.RunProcedureReturnString("sp_EditCrmDeliverHrState", _Parameters1, out iResult);

                if (strSql == "1")
                {
                    string msg1 = workFlowServiceClient.Run(this.User.LoginName, strOperatorInstanceId, "提交");
                    HttpContext.Current.Response.Write("1");
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 内训-更新
        /// </summary>
        /// <param name="strJson"></param>
        private void UpdateCrmDeliverTrain(string strJson)
        {
            strJson = this.GetStringFromQueryString("id", "");//大课ID
            //string PM = this.GetStringFromQueryString("PM", ""); //项目经理ID
            string BeginDate = this.GetStringFromQueryString("BeginDate", "");//启动日期
            string PMemember = this.GetStringFromQueryString("PMemember", "");//项目成员
            string PExplain = this.GetStringFromQueryString("PExplain", "");//备注
            string ProjectUser = this.GetStringFromQueryString("ProjectUser", "");//添加用户
            string ProjectDate = this.GetStringFromQueryString("ProjectDate", "");
            string strOperatorInstanceId = this.GetStringFromQueryString("oid", ""); //流程操作ID
            string strWorkTaskInsId = this.GetStringFromQueryString("tid", ""); //流程任务ID
            string strView = this.GetStringFromQueryString("view", "");
            string orderid = this.GetStringFromQueryString("orderid", "");
            string stateId = this.GetStringFromQueryString("stateId", "");
            string productid = this.GetStringFromQueryString("productid", "");
            try
            {

                string strSql = "";
                if (strView != "1")
                {
                    strSql = string.Format("update CrmDeliverTrain set DliverState='" + stateId + "' , BeginDate='" + BeginDate + "',PTeacher='" + PMemember + "', Explain='" + PExplain + "',StartUser='" + ProjectUser + "',StartDate='" + ProjectDate + "' where ID='" + strJson + "'");
                }
                else
                {
                    strSql = string.Format("update CrmDeliverTrain set DliverState='" + stateId + "' ,BeginDate='" + BeginDate + "',PTeacher='" + PMemember + "', Explain='" + PExplain + "' where ID='" + strJson + "'");
                }
                int iResult = bll.RunSqlCommand(strSql);
                if (iResult > 0)
                {
                    bll.RunSqlCommand("update CrmCustomerOrder set StateID='eda4faa9-8544-494c-bf1c-02662e1078a6' where ID='" + orderid + "'");
                    bll.RunSqlCommand("update CrmOrderProduct set StateId='EDA4FAA9-8544-494C-BF1C-02662E1078A6' where OrderID='" + orderid + "' and ProductId='" + productid + "'");
                    string msg1 = workFlowServiceClient.Run(this.User.LoginName, strOperatorInstanceId, "提交");
                    HttpContext.Current.Response.Write("1");
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 英才学校-更新
        /// </summary>
        /// <param name="strJson"></param>
        private void UpdateCrmDeliverHr(string strJson)
        {
            strJson = this.GetStringFromQueryString("id", "");//大课ID
            //string PM = this.GetStringFromQueryString("PM", ""); //项目经理ID
            string BeginDate = this.GetStringFromQueryString("BeginDate", "");//启动日期
            string PMemember = this.GetStringFromQueryString("PMemember", "");//项目成员
            string PExplain = this.GetStringFromQueryString("PExplain", "");//备注
            string ApplicantUser = this.GetStringFromQueryString("ApplicantUser", "");//添加用户
            string ApplicantDate = this.GetStringFromQueryString("ApplicantDate", "");
            string strOperatorInstanceId = this.GetStringFromQueryString("oid", ""); //流程操作ID
            string strWorkTaskInsId = this.GetStringFromQueryString("tid", ""); //流程任务ID
            string strView = this.GetStringFromQueryString("view", "");
            string orderid = this.GetStringFromQueryString("orderid", "");
            string stateId = this.GetStringFromQueryString("stateId", "");
            string productid = this.GetStringFromQueryString("productid", "");
            try
            {
                int yzNum = bll.RunSqlCommand("declare @termId uniqueidentifier  select @termId=termid from CrmDeliverHr where id='" + strJson + "' update CrmDeliverHrTerm set TermExistNum=TermExistNum+" + int.Parse(GetStringFromQueryString("num", "")) + " where ID=@termId and TermNum>=TermExistNum+" + int.Parse(GetStringFromQueryString("num", "")));
                if (yzNum > 0)
                {
                    string strSql = "";
                    if (strView != "1")
                    {
                        strSql = string.Format("update CrmDeliverHr set  DliverState='" + stateId + "' where ID='" + strJson + "'");
                    }
                    else
                    {
                        strSql = string.Format("update CrmDeliverHr set  DliverState='" + stateId + "' where ID='" + strJson + "'");
                    }
                    int iResult = bll.RunSqlCommand(strSql);
                    if (iResult > 0)
                    {
                        bll.RunSqlCommand("update CrmMajorStudentHr set StudentState=0 where MajorID=(select top 1 ID from CrmDeliverHr where id='" + strJson + "')");
                        bll.RunSqlCommand("update CrmCustomerOrder set StateID='eda4faa9-8544-494c-bf1c-02662e1078a6' where ID='" + orderid + "'");
                        bll.RunSqlCommand("update CrmOrderProduct set StateId='EDA4FAA9-8544-494C-BF1C-02662E1078A6' where OrderID='" + orderid + "' and ProductId='" + productid + "'");

                        string msg1 = workFlowServiceClient.Run(this.User.LoginName, strOperatorInstanceId, "提交");
                        HttpContext.Current.Response.Write("1");
                    }
                }
                else
                {
                    HttpContext.Current.Response.Write("该期课程已满，如需审批！请调整“期数名额”，如不审批请退回客户经理进行“改期”");
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 内训-更新市场部
        /// </summary>
        /// <param name="strJson"></param>
        private void UpdateCrmDeliverTrainScb(string strJson)
        {
            strJson = this.GetStringFromQueryString("id", "");//大课ID
            string InnerValue = this.GetStringFromQueryString("InnerValue", ""); //
            string OutValue = this.GetStringFromQueryString("OutValue", ""); //
            string WellDegree = this.GetStringFromQueryString("WellDegree", "");//
            string exp = this.GetStringFromQueryString("exp", "");//
            string DegreeUser = this.GetStringFromQueryString("DegreeUser", "");//添加用户
            string DegreeDate = this.GetStringFromQueryString("DegreeDate", "");
            string strOperatorInstanceId = this.GetStringFromQueryString("oid", ""); //流程操作ID
            string strWorkTaskInsId = this.GetStringFromQueryString("tid", ""); //流程任务ID
            try
            {
                string strSql = string.Format("update CrmDeliverTrain set OutValue='" + OutValue + "',exp3=" + exp + ", InnerValue='" + InnerValue + "' ,WellDegree=" + WellDegree + ", DegreeUser='" + DegreeUser + "',DegreeDate='" + DegreeDate + "' where ID='" + strJson + "'");
                int iResult = bll.RunSqlCommand(strSql);

                if (iResult > 0)
                {
                    string msg1 = workFlowServiceClient.Run(this.User.LoginName, strOperatorInstanceId, "提交");
                    HttpContext.Current.Response.Write("1");
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex.ToString());
            }
        }
        /// <summary>
        /// 英才学校 资格审核
        /// </summary>
        /// <param name="strJson"></param>
        private void UpdateCrmDeliverHrZgsh(string strJson)
        {
            string strOperatorInstanceId = this.GetStringFromQueryString("oid", ""); //流程操作ID
            string stateId = this.GetStringFromQueryString("stateId", "");//状态ID
            string majorID = this.GetStringFromQueryString("id", "");//MajorID
            try
            {
                string strSql = string.Format("update CrmDeliverHr set DliverState='" + stateId + "' where ID='" + majorID + "'");
                bll.RunSqlCommand(strSql);
                string msg1 = workFlowServiceClient.Run(this.User.LoginName, strOperatorInstanceId, "提交");
                HttpContext.Current.Response.Write("1");

            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex.ToString());
            }
        }
        /// <summary>
        /// 更新客户数据(联动更新)
        /// </summary>
        /// <param name="strJson"></param>
        private void UpdateCustomerProduce(string strJson)
        {
            try
            {
                int iResult = 0;
                IDataParameter[] _Parameters = new IDataParameter[] { };
                DbSql db = new DbSql();
                string strCompanyCreateDate = "", strExp3 = "", strExp4 = "", strDrink = "";
                DateTime strDecisionBirthday;
                CrmCustomerInfo instance = (CrmCustomerInfo)Globals.JSonToObject<CrmCustomerInfo>(strJson);
                if (instance.CompanyCreateDate.ToString().Trim() == "0001-1-1 0:00:00" ||
                    instance.CompanyCreateDate.ToString().Trim() == "0001-1-1 00:00:00" ||
                   instance.CompanyCreateDate.ToString() == "")
                {
                    strCompanyCreateDate = "1900-01-01";
                }
                else
                {
                    strCompanyCreateDate = instance.CompanyCreateDate.ToString();
                }
                if (instance.DecisionBirthday.ToString().Trim() == "0001-1-1 0:00:00" ||
                    instance.DecisionBirthday.ToString().Trim() == "0001-1-1 00:00:00" ||
                    instance.DecisionBirthday.ToString() == "")
                {
                    strDecisionBirthday = DateTime.Parse("1900-01-01");
                }
                else
                {
                    strDecisionBirthday = instance.DecisionBirthday;
                }
                strExp3 = strDecisionBirthday.Year.ToString();
                strExp4 = strDecisionBirthday.Month.ToString();
                strDrink = strDecisionBirthday.Day.ToString();

                SqlParameter ID = new SqlParameter("@ID", SqlDbType.UniqueIdentifier, 50);
                ID.Direction = ParameterDirection.Input;
                ID.Value = instance.ID;
                SqlParameter CustomerName = new SqlParameter("@CustomerName", SqlDbType.NVarChar, 50);
                CustomerName.Direction = ParameterDirection.Input;
                CustomerName.Value = instance.CustomerName;
                SqlParameter Address = new SqlParameter("@Address", SqlDbType.NVarChar, 100);
                Address.Direction = ParameterDirection.Input;
                Address.Value = instance.Address;
                SqlParameter State = new SqlParameter("@State", SqlDbType.NVarChar, 30);
                State.Direction = ParameterDirection.Input;
                State.Value = instance.State;
                SqlParameter Province = new SqlParameter("@Province", SqlDbType.NVarChar, 20);
                Province.Direction = ParameterDirection.Input;
                Province.Value = instance.Province;
                SqlParameter City = new SqlParameter("@City", SqlDbType.NVarChar, 20);
                City.Direction = ParameterDirection.Input;
                City.Value = instance.City;
                SqlParameter Area = new SqlParameter("@Area", SqlDbType.NVarChar, 20);
                Area.Direction = ParameterDirection.Input;
                Area.Value = instance.Area;
                SqlParameter Decisionmaker = new SqlParameter("@Decisionmaker", SqlDbType.NVarChar, 30);
                Decisionmaker.Direction = ParameterDirection.Input;
                Decisionmaker.Value = instance.Decisionmaker;
                SqlParameter DecisionTel = new SqlParameter("@DecisionTel", SqlDbType.NVarChar, 20);
                DecisionTel.Direction = ParameterDirection.Input;
                DecisionTel.Value = instance.DecisionTel;
                SqlParameter DecisionPosition = new SqlParameter("@DecisionPosition", SqlDbType.NVarChar, 20);
                DecisionPosition.Direction = ParameterDirection.Input;
                DecisionPosition.Value = instance.DecisionPosition;
                SqlParameter DecisionSex = new SqlParameter("@DecisionSex", SqlDbType.Char, 1);
                DecisionSex.Direction = ParameterDirection.Input;
                DecisionSex.Value = instance.DecisionSex;
                SqlParameter CompanyProduct = new SqlParameter("@CompanyProduct", SqlDbType.NVarChar, 100);
                CompanyProduct.Direction = ParameterDirection.Input;
                CompanyProduct.Value = instance.CompanyProduct;
                SqlParameter Tel1 = new SqlParameter("@Tel1", SqlDbType.NVarChar, 20);
                Tel1.Direction = ParameterDirection.Input;
                Tel1.Value = instance.Tel1;
                SqlParameter Tel2 = new SqlParameter("@Tel2", SqlDbType.NVarChar, 20);
                Tel2.Direction = ParameterDirection.Input;
                Tel2.Value = instance.Tel2;
                SqlParameter DecisionEmail = new SqlParameter("@DecisionEmail", SqlDbType.NVarChar, 30);
                DecisionEmail.Direction = ParameterDirection.Input;
                DecisionEmail.Value = instance.DecisionEmail;
                SqlParameter Post = new SqlParameter("@Post", SqlDbType.NVarChar, 30);
                Post.Direction = ParameterDirection.Input;
                Post.Value = instance.Post;
                SqlParameter CompanyAttention = new SqlParameter("@CompanyAttention", SqlDbType.NVarChar, 100);
                CompanyAttention.Direction = ParameterDirection.Input;
                CompanyAttention.Value = instance.CompanyAttention;
                SqlParameter CusTestimony = new SqlParameter("@CusTestimony", SqlDbType.NVarChar, 50);
                CusTestimony.Direction = ParameterDirection.Input;
                CusTestimony.Value = instance.CusTestimony;
                SqlParameter Fax = new SqlParameter("@Fax", SqlDbType.NVarChar, 20);
                Fax.Direction = ParameterDirection.Input;
                Fax.Value = instance.Fax;
                SqlParameter CompanyCreateDate = new SqlParameter("@CompanyCreateDate", SqlDbType.DateTime, 50);
                CompanyCreateDate.Direction = ParameterDirection.Input;
                CompanyCreateDate.Value = strCompanyCreateDate;
                SqlParameter Email = new SqlParameter("@Email", SqlDbType.NVarChar, 30);
                Email.Direction = ParameterDirection.Input;
                Email.Value = instance.Email;
                SqlParameter CompanyNetting = new SqlParameter("@CompanyNetting", SqlDbType.NVarChar, 30);
                CompanyNetting.Direction = ParameterDirection.Input;
                CompanyNetting.Value = instance.CompanyNetting;
                SqlParameter MnemonicCode = new SqlParameter("@MnemonicCode", SqlDbType.NVarChar, 30);
                MnemonicCode.Direction = ParameterDirection.Input;
                MnemonicCode.Value = instance.MnemonicCode;
                SqlParameter PersonId = new SqlParameter("@PersonId", SqlDbType.UniqueIdentifier, 50);
                PersonId.Direction = ParameterDirection.Input;
                PersonId.Value = instance.PersonId;
                SqlParameter AreaId = new SqlParameter("@AreaId", SqlDbType.UniqueIdentifier, 50);
                AreaId.Direction = ParameterDirection.Input;
                AreaId.Value = instance.AreaId;
                SqlParameter TypeId = new SqlParameter("@TypeId", SqlDbType.UniqueIdentifier, 50);
                TypeId.Direction = ParameterDirection.Input;
                TypeId.Value = instance.TypeId;
                SqlParameter TradeId = new SqlParameter("@TradeId", SqlDbType.UniqueIdentifier, 50);
                TradeId.Direction = ParameterDirection.Input;
                TradeId.Value = instance.TradeId;
                SqlParameter ProductId = new SqlParameter("@ProductId", SqlDbType.UniqueIdentifier, 50);
                ProductId.Direction = ParameterDirection.Input;
                ProductId.Value = instance.ProductId;
                SqlParameter OriginId = new SqlParameter("@OriginId", SqlDbType.UniqueIdentifier, 50);
                OriginId.Direction = ParameterDirection.Input;
                OriginId.Value = instance.OriginId;
                SqlParameter PropertyId = new SqlParameter("@PropertyId", SqlDbType.UniqueIdentifier, 50);
                PropertyId.Direction = ParameterDirection.Input;
                PropertyId.Value = instance.PropertyId;
                SqlParameter LevelId = new SqlParameter("@LevelId", SqlDbType.UniqueIdentifier, 50);
                LevelId.Direction = ParameterDirection.Input;
                LevelId.Value = instance.LevelId;
                SqlParameter UnionId = new SqlParameter("@UnionId", SqlDbType.NVarChar, 100);
                UnionId.Direction = ParameterDirection.Input;
                UnionId.Value = instance.UnionId;
                SqlParameter ManagerQuestion = new SqlParameter("@ManagerQuestion", SqlDbType.NVarChar, 500);
                ManagerQuestion.Direction = ParameterDirection.Input;
                ManagerQuestion.Value = instance.ManagerQuestion;
                SqlParameter StrongPoint = new SqlParameter("@StrongPoint", SqlDbType.NVarChar, 200);
                StrongPoint.Direction = ParameterDirection.Input;
                StrongPoint.Value = instance.StrongPoint;
                SqlParameter Explain = new SqlParameter("@Explain", SqlDbType.NVarChar, 500);
                Explain.Direction = ParameterDirection.Input;
                Explain.Value = instance.Explain;
                SqlParameter Homeplace = new SqlParameter("@Homeplace", SqlDbType.NVarChar, 20);
                Homeplace.Direction = ParameterDirection.Input;
                Homeplace.Value = instance.Homeplace;
                SqlParameter BirthdayType = new SqlParameter("@BirthdayType", SqlDbType.Char, 1);
                BirthdayType.Direction = ParameterDirection.Input;
                BirthdayType.Value = instance.BirthdayType;
                SqlParameter Birthday = new SqlParameter("@Birthday", SqlDbType.DateTime, 50);
                Birthday.Direction = ParameterDirection.Input;
                Birthday.Value = strDecisionBirthday;
                SqlParameter LinkManFancy = new SqlParameter("@LinkManFancy", SqlDbType.NVarChar, 30);
                LinkManFancy.Direction = ParameterDirection.Input;
                LinkManFancy.Value = instance.DecisionFancy;
                SqlParameter EXP3 = new SqlParameter("@EXP3", SqlDbType.NVarChar, 40);
                EXP3.Direction = ParameterDirection.Input;
                EXP3.Value = strExp3;
                SqlParameter EXP4 = new SqlParameter("@EXP4", SqlDbType.NVarChar, 40);
                EXP4.Direction = ParameterDirection.Input;
                EXP4.Value = strExp4;
                SqlParameter Drink = new SqlParameter("@Drink", SqlDbType.NVarChar, 20);
                Drink.Direction = ParameterDirection.Input;
                Drink.Value = strDrink;
                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;

                _Parameters = new IDataParameter[] { ID, CustomerName, Address, State, Province,
                                                    City, Area, Decisionmaker, DecisionTel, DecisionPosition, DecisionSex, 
                                                    CompanyProduct, Tel1, Tel2, DecisionEmail, Post, CompanyAttention, 
                                                    CusTestimony, Fax, CompanyCreateDate, Email,  CompanyNetting, 
                                                    MnemonicCode, PersonId, AreaId, TypeId, TradeId, ProductId, 
                                                    OriginId, PropertyId, LevelId, UnionId, ManagerQuestion,
                                                    StrongPoint, Explain, Homeplace, BirthdayType, Birthday,
                                                    LinkManFancy, EXP3, EXP4, Drink, ReturnValue};
                string strSql = db.RunProcedureReturnString("sp_UpdateCustomer", _Parameters, out iResult);
                if (strSql == "1")
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("0");
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 更新客户信息数据(联动更新)
        /// </summary>
        /// <param name="strJson"></param>
        private void UpdateCustomerInfoProduce(string strJson)
        {
            try
            {
                int iResult = 0;
                IDataParameter[] _Parameters = new IDataParameter[] { };
                DbSql db = new DbSql();
                string strCompanyCreateDate = "", strExp3 = "", strExp4 = "", strDrink = "";
                DateTime strDecisionBirthday;
                CrmCustomerInfo instance = (CrmCustomerInfo)Globals.JSonToObject<CrmCustomerInfo>(strJson);
                if (instance.CompanyCreateDate.ToString().Trim() == "0001-1-1 0:00:00" ||
                    instance.CompanyCreateDate.ToString().Trim() == "0001-1-1 00:00:00" ||
                   instance.CompanyCreateDate.ToString() == "")
                {
                    strCompanyCreateDate = "1900-01-01";
                }
                else
                {
                    strCompanyCreateDate = instance.CompanyCreateDate.ToString();
                }
                if (instance.DecisionBirthday.ToString().Trim() == "0001-1-1 0:00:00" ||
                    instance.DecisionBirthday.ToString().Trim() == "0001-1-1 00:00:00" ||
                    instance.DecisionBirthday.ToString() == "")
                {
                    strDecisionBirthday = DateTime.Parse("1900-01-01");
                }
                else
                {
                    strDecisionBirthday = instance.DecisionBirthday;
                }
                strExp3 = strDecisionBirthday.Year.ToString();
                strExp4 = strDecisionBirthday.Month.ToString();
                strDrink = strDecisionBirthday.Day.ToString();

                SqlParameter ID = new SqlParameter("@ID", SqlDbType.UniqueIdentifier, 50);
                ID.Direction = ParameterDirection.Input;
                ID.Value = instance.ID;
                SqlParameter CustomerName = new SqlParameter("@CustomerName", SqlDbType.NVarChar, 50);
                CustomerName.Direction = ParameterDirection.Input;
                CustomerName.Value = instance.CustomerName;
                SqlParameter Address = new SqlParameter("@Address", SqlDbType.NVarChar, 100);
                Address.Direction = ParameterDirection.Input;
                Address.Value = instance.Address;
                SqlParameter State = new SqlParameter("@State", SqlDbType.NVarChar, 30);
                State.Direction = ParameterDirection.Input;
                State.Value = instance.State;
                SqlParameter Province = new SqlParameter("@Province", SqlDbType.NVarChar, 20);
                Province.Direction = ParameterDirection.Input;
                Province.Value = instance.Province;
                SqlParameter City = new SqlParameter("@City", SqlDbType.NVarChar, 20);
                City.Direction = ParameterDirection.Input;
                City.Value = instance.City;
                SqlParameter Area = new SqlParameter("@Area", SqlDbType.NVarChar, 20);
                Area.Direction = ParameterDirection.Input;
                Area.Value = instance.Area;
                SqlParameter Decisionmaker = new SqlParameter("@Decisionmaker", SqlDbType.NVarChar, 30);
                Decisionmaker.Direction = ParameterDirection.Input;
                Decisionmaker.Value = instance.Decisionmaker;
                SqlParameter DecisionTel = new SqlParameter("@DecisionTel", SqlDbType.NVarChar, 20);
                DecisionTel.Direction = ParameterDirection.Input;
                DecisionTel.Value = instance.DecisionTel;
                SqlParameter DecisionPosition = new SqlParameter("@DecisionPosition", SqlDbType.NVarChar, 20);
                DecisionPosition.Direction = ParameterDirection.Input;
                DecisionPosition.Value = instance.DecisionPosition;
                SqlParameter DecisionSex = new SqlParameter("@DecisionSex", SqlDbType.Char, 1);
                DecisionSex.Direction = ParameterDirection.Input;
                DecisionSex.Value = instance.DecisionSex;
                SqlParameter CompanyProduct = new SqlParameter("@CompanyProduct", SqlDbType.NVarChar, 100);
                CompanyProduct.Direction = ParameterDirection.Input;
                CompanyProduct.Value = instance.CompanyProduct;
                SqlParameter Tel1 = new SqlParameter("@Tel1", SqlDbType.NVarChar, 20);
                Tel1.Direction = ParameterDirection.Input;
                Tel1.Value = instance.Tel1;
                SqlParameter Tel2 = new SqlParameter("@Tel2", SqlDbType.NVarChar, 20);
                Tel2.Direction = ParameterDirection.Input;
                Tel2.Value = instance.Tel2;
                SqlParameter DecisionEmail = new SqlParameter("@DecisionEmail", SqlDbType.NVarChar, 30);
                DecisionEmail.Direction = ParameterDirection.Input;
                DecisionEmail.Value = instance.DecisionEmail;
                SqlParameter Post = new SqlParameter("@Post", SqlDbType.NVarChar, 30);
                Post.Direction = ParameterDirection.Input;
                Post.Value = instance.Post;
                SqlParameter CompanyAttention = new SqlParameter("@CompanyAttention", SqlDbType.NVarChar, 100);
                CompanyAttention.Direction = ParameterDirection.Input;
                CompanyAttention.Value = instance.CompanyAttention;
                SqlParameter CusTestimony = new SqlParameter("@CusTestimony", SqlDbType.NVarChar, 50);
                CusTestimony.Direction = ParameterDirection.Input;
                CusTestimony.Value = instance.CusTestimony;
                SqlParameter Fax = new SqlParameter("@Fax", SqlDbType.NVarChar, 20);
                Fax.Direction = ParameterDirection.Input;
                Fax.Value = instance.Fax;
                SqlParameter CompanyCreateDate = new SqlParameter("@CompanyCreateDate", SqlDbType.DateTime, 50);
                CompanyCreateDate.Direction = ParameterDirection.Input;
                CompanyCreateDate.Value = strCompanyCreateDate;
                SqlParameter Email = new SqlParameter("@Email", SqlDbType.NVarChar, 30);
                Email.Direction = ParameterDirection.Input;
                Email.Value = instance.Email;
                SqlParameter CompanyNetting = new SqlParameter("@CompanyNetting", SqlDbType.NVarChar, 30);
                CompanyNetting.Direction = ParameterDirection.Input;
                CompanyNetting.Value = instance.CompanyNetting;
                SqlParameter MnemonicCode = new SqlParameter("@MnemonicCode", SqlDbType.NVarChar, 30);
                MnemonicCode.Direction = ParameterDirection.Input;
                MnemonicCode.Value = instance.MnemonicCode;
                SqlParameter PersonId = new SqlParameter("@PersonId", SqlDbType.UniqueIdentifier, 50);
                PersonId.Direction = ParameterDirection.Input;
                PersonId.Value = instance.PersonId;
                SqlParameter AreaId = new SqlParameter("@AreaId", SqlDbType.UniqueIdentifier, 50);
                AreaId.Direction = ParameterDirection.Input;
                AreaId.Value = instance.AreaId;
                SqlParameter TypeId = new SqlParameter("@TypeId", SqlDbType.UniqueIdentifier, 50);
                TypeId.Direction = ParameterDirection.Input;
                TypeId.Value = instance.TypeId;
                SqlParameter TradeId = new SqlParameter("@TradeId", SqlDbType.UniqueIdentifier, 50);
                TradeId.Direction = ParameterDirection.Input;
                TradeId.Value = instance.TradeId;
                SqlParameter ProductId = new SqlParameter("@ProductId", SqlDbType.UniqueIdentifier, 50);
                ProductId.Direction = ParameterDirection.Input;
                ProductId.Value = instance.ProductId;
                SqlParameter OriginId = new SqlParameter("@OriginId", SqlDbType.UniqueIdentifier, 50);
                OriginId.Direction = ParameterDirection.Input;
                OriginId.Value = instance.OriginId;
                SqlParameter PropertyId = new SqlParameter("@PropertyId", SqlDbType.UniqueIdentifier, 50);
                PropertyId.Direction = ParameterDirection.Input;
                PropertyId.Value = instance.PropertyId;
                SqlParameter LevelId = new SqlParameter("@LevelId", SqlDbType.UniqueIdentifier, 50);
                LevelId.Direction = ParameterDirection.Input;
                LevelId.Value = instance.LevelId;
                SqlParameter UnionId = new SqlParameter("@UnionId", SqlDbType.NVarChar, 100);
                UnionId.Direction = ParameterDirection.Input;
                UnionId.Value = instance.UnionId;
                SqlParameter ManagerQuestion = new SqlParameter("@ManagerQuestion", SqlDbType.NVarChar, 500);
                ManagerQuestion.Direction = ParameterDirection.Input;
                ManagerQuestion.Value = instance.ManagerQuestion;
                SqlParameter StrongPoint = new SqlParameter("@StrongPoint", SqlDbType.NVarChar, 200);
                StrongPoint.Direction = ParameterDirection.Input;
                StrongPoint.Value = instance.StrongPoint;
                SqlParameter Explain = new SqlParameter("@Explain", SqlDbType.NVarChar, 500);
                Explain.Direction = ParameterDirection.Input;
                Explain.Value = instance.Explain;
                SqlParameter Birthday = new SqlParameter("@Birthday", SqlDbType.DateTime, 50);
                Birthday.Direction = ParameterDirection.Input;
                Birthday.Value = strDecisionBirthday;
                SqlParameter EXP3 = new SqlParameter("@EXP3", SqlDbType.NVarChar, 40);
                EXP3.Direction = ParameterDirection.Input;
                EXP3.Value = strExp3;
                SqlParameter EXP4 = new SqlParameter("@EXP4", SqlDbType.NVarChar, 40);
                EXP4.Direction = ParameterDirection.Input;
                EXP4.Value = strExp4;
                SqlParameter Drink = new SqlParameter("@Drink", SqlDbType.NVarChar, 20);
                Drink.Direction = ParameterDirection.Input;
                Drink.Value = strDrink;
                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;

                _Parameters = new IDataParameter[] { ID, CustomerName, Address, State, Province,
                                                    City, Area, Decisionmaker, DecisionTel, DecisionPosition, DecisionSex, 
                                                    CompanyProduct, Tel1, Tel2, DecisionEmail, Post, CompanyAttention, 
                                                    CusTestimony, Fax, CompanyCreateDate, Email,  CompanyNetting, 
                                                    MnemonicCode, PersonId, AreaId, TypeId, TradeId, ProductId, 
                                                    OriginId, PropertyId, LevelId, UnionId, ManagerQuestion,
                                                    StrongPoint, Explain,Birthday,EXP3,EXP4,Drink,ReturnValue};
                string strSql = db.RunProcedureReturnString("sp_UpdateCustomerInfo", _Parameters, out iResult);
                if (strSql == "1")
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write(strSql);
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 学员分团
        /// </summary>
        /// <param name="strJson"></param>
        private void UpdateCrmMajorStudentGroup(string strJson)
        {
            try
            {
                CrmMajorStudent student = (CrmMajorStudent)Globals.JSonToObject<CrmMajorStudent>(strJson);
                string[] strIds = student.Exp1.Split('#');
                string strGroupName = student.GroupName;
                string strAssistance = student.Assistance.ToString();
                string strExplain = student.Explain;
                for (int i = 0; i < strIds.Length - 1; i++)
                {
                    int iResult = 0;
                    IDataParameter[] _Parameters = new IDataParameter[] { };
                    DbSql db = new DbSql();
                    SqlParameter StudentId = new SqlParameter("@StudentId", SqlDbType.UniqueIdentifier, 50);
                    StudentId.Direction = ParameterDirection.Input;
                    StudentId.Value = new Guid(strIds[i]);
                    SqlParameter GroupName = new SqlParameter("@GroupName", SqlDbType.NVarChar, 30);
                    GroupName.Direction = ParameterDirection.Input;
                    GroupName.Value = strGroupName;
                    SqlParameter Assistance = new SqlParameter("@Assistance", SqlDbType.UniqueIdentifier, 50);
                    Assistance.Direction = ParameterDirection.Input;
                    Assistance.Value = new Guid(strAssistance);
                    SqlParameter Explain = new SqlParameter("@Explain", SqlDbType.NVarChar, 50);
                    Explain.Direction = ParameterDirection.Input;
                    Explain.Value = strExplain;
                    SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                    ReturnValue.Direction = ParameterDirection.Output;
                    _Parameters = new IDataParameter[] { StudentId, GroupName, Assistance, Explain, ReturnValue };
                    string strSql = db.RunProcedureReturnString("sp_UpdateCrmMajorStudentGroup", _Parameters, out iResult);

                }
                HttpContext.Current.Response.Write("1");
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 客户操作(公海客户直接到客户信息,客户信息直接到公海)
        /// </summary>
        private void UpdateCrmCustomeToCustomerInfo()
        {
            try
            {
                string strID = this.GetStringFromQueryString("id", "");
                string strType = this.GetStringFromQueryString("type", "");
                int iResult = 0;
                IDataParameter[] _Parameters = new IDataParameter[] { };
                DbSql db = new DbSql();
                SqlParameter CustomerId = new SqlParameter("@CustomerId", SqlDbType.UniqueIdentifier, 50);
                CustomerId.Direction = ParameterDirection.Input;
                CustomerId.Value = new Guid(strID);
                SqlParameter Type = new SqlParameter("@Type", SqlDbType.Int, 1);
                Type.Direction = ParameterDirection.Input;
                Type.Value = int.Parse(strType);
                SqlParameter AddUser = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
                AddUser.Direction = ParameterDirection.Input;
                AddUser.Value = new Guid(this.UserId.ToString());
                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;
                _Parameters = new IDataParameter[] { CustomerId, Type, AddUser, ReturnValue };
                string strSql = db.RunProcedureReturnString("sp_UpdateCrmCustomerToCustomerInfo", _Parameters, out iResult);
                if (strSql == "1")
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write(strSql);
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 设置用户课程规划角色
        /// </summary>
        /// <param name="strJson"></param>
        private void UpdateCrmProductLayoutRole(string strJson)
        {
            try
            {
                TempProductLayout instance = (TempProductLayout)Globals.JSonToObject<TempProductLayout>(strJson);
                string UserId = instance.UserId.Replace("[", "").Replace("]", "");
                string ProductRoleId = instance.ProductLayoutId.Replace("[", "").Replace("]", "");
                string[] ArrayUserId = UserId.Split(',');
                string[] ArrayRoleId = ProductRoleId.Split(',');
                for (int i = 0; i < ArrayUserId.Length; i++)
                {
                    string strDelete = string.Format("delete CrmProductLayoutRole where ProductRoleID='00000000-0000-0000-0000-000000000000' and UserId='" + ArrayUserId[i] + "'");
                    int iCount = bll.RunSqlCommand(strDelete);
                    for (int j = 0; j < ArrayRoleId.Length; j++)
                    {
                        string strSql = string.Format("Exec sp_UpdateCrmProductLayout '{0}','{1}','{2}'", ArrayUserId[i], ArrayRoleId[j], this.UserId);
                        int iResult = bll.RunSqlCommand(strSql);
                        if (iResult > 0)
                        {
                        }
                    }
                }
                HttpContext.Current.Response.Write("1");
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        private class TempProductLayout
        {
            private string _UserId;
            public string UserId
            {
                get { return _UserId; }
                set { _UserId = value; }
            }
            private string _ProductLayoutId;
            public string ProductLayoutId
            {
                get { return _ProductLayoutId; }
                set { _ProductLayoutId = value; }
            }
        }
        /// <summary>
        /// 移至客户数据到公海表
        /// </summary>
        private void UpdateCrmCustomerOld()
        {
            try
            {
                string strId = this.GetStringFromQueryString("id", "");
                string strCustomerCode = IDMaker.GetSequenceStr("CUS001");

                int iResult = 0;
                IDataParameter[] _Parameters = new IDataParameter[] { };
                DbSql db = new DbSql();
                SqlParameter CustomerOldId = new SqlParameter("@CustomerOldId", SqlDbType.UniqueIdentifier, 50);
                CustomerOldId.Direction = ParameterDirection.Input;
                CustomerOldId.Value = new Guid(strId);
                SqlParameter CustomerCode = new SqlParameter("@CustomerCode", SqlDbType.Char, 15);
                CustomerCode.Direction = ParameterDirection.Input;
                CustomerCode.Value = strCustomerCode;
                SqlParameter AddUser = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
                AddUser.Direction = ParameterDirection.Input;
                AddUser.Value = new Guid(this.UserId.ToString());
                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;
                _Parameters = new IDataParameter[] { CustomerOldId, CustomerCode, AddUser, ReturnValue };
                string strSql = db.RunProcedureReturnString("sp_MoveCustomerOldToCustomer", _Parameters, out iResult);
                if (strSql == "1")
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write(strSql);
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 移动客户数据 将数据废弃
        /// </summary>
        private void UpdateCrmCustomerOldd()
        {
            try
            {
                string strIds = this.GetStringFromQueryString("ids", "");
                string strExplain = this.GetStringFromQueryString("explain", "");

                string[] IdsList = strIds.Split(',');
                for (int i = 0; i < IdsList.Length; i++)
                {
                    string strSql = string.Format("update CrmCustomerOld set CustomerState=2,Explain='{1}'," +
                                            "ModifyUser='{2}',ModifyDate='{3}' where ID='{0}'",
                                            IdsList[i].ToString(), strExplain, this.UserId.ToString(), DateTime.Now.ToString());
                    int iResult = bll.RunSqlCommand(strSql);
                    if (iResult > 0)
                    {
                        continue;
                    }
                    else
                    {
                        HttpContext.Current.Response.Write("数据更新状态为2失败!");
                        return;
                    }
                }
                HttpContext.Current.Response.Write("1");
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 更新学员团号和顺序号
        /// </summary>
        private void UpdateCrmStudentGroupNameAndGroupNumber()
        {
            try
            {
                int iResult = 0;
                IDataParameter[] _Parameters = new IDataParameter[] { };
                DbSql db = new DbSql();
                BaseBussnies bll = new BaseBussnies();
                string strProductLayoutId = this.GetStringFromQueryString("pid", "");//课程规划ID
                string strId = this.GetStringFromQueryString("id", ""); //学员ID
                string strName = this.GetStringFromQueryString("name", ""); //团号
                string strNumber = this.GetStringFromQueryString("number", "");  //序号号

                SqlParameter ProductLayoutID = new SqlParameter("@ProductLayoutID", SqlDbType.UniqueIdentifier, 50);
                ProductLayoutID.Direction = ParameterDirection.Input;
                ProductLayoutID.Value = new Guid(strProductLayoutId);
                SqlParameter StudentId = new SqlParameter("@StudentId", SqlDbType.UniqueIdentifier, 50);
                StudentId.Direction = ParameterDirection.Input;
                StudentId.Value = new Guid(strId);
                SqlParameter GroupName = new SqlParameter("@GroupName", SqlDbType.NVarChar, 50);
                GroupName.Direction = ParameterDirection.Input;
                GroupName.Value = strName;
                SqlParameter GroupNumber = new SqlParameter("@GroupNumber", SqlDbType.NVarChar, 50);
                GroupNumber.Direction = ParameterDirection.Input;
                GroupNumber.Value = strNumber;
                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;

                _Parameters = new IDataParameter[] { ProductLayoutID, StudentId, GroupName, GroupNumber, ReturnValue };
                string strSql = db.RunProcedureReturnString("sp_UpdateCrmStudentGroupName", _Parameters, out iResult);
                if (strSql == "1")
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write(strSql);
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 更新学员团号和顺序号
        /// </summary>
        private void UpdateBudgetMasteAccount()
        {
            try
            {
                int iResult = 0;
                IDataParameter[] _Parameters = new IDataParameter[] { };
                DbSql db = new DbSql();
                BaseBussnies bll = new BaseBussnies();
                string strId = this.GetStringFromQueryString("id", ""); //费用ID
                string strConferenceActualAmount = this.GetStringFromQueryString("ConferenceActualAmount", ""); //会务实际金额
                string strFinancialActualAmount = this.GetStringFromQueryString("FinancialActualAmount", "");  //财务实际金额
                string strFlag = this.GetStringFromQueryString("flag", ""); //财务，会务 审核

                SqlParameter Id = new SqlParameter("@Id", SqlDbType.UniqueIdentifier, 50);
                Id.Direction = ParameterDirection.Input;
                Id.Value = new Guid(strId);
                SqlParameter ConferenceActualAmount = new SqlParameter("@ConferenceActualAmount", SqlDbType.Decimal, 18);
                ConferenceActualAmount.Direction = ParameterDirection.Input;
                ConferenceActualAmount.Value = Convert.ToDecimal(strConferenceActualAmount);
                SqlParameter FinancialActualAmount = new SqlParameter("@FinancialActualAmount", SqlDbType.Decimal, 18);
                FinancialActualAmount.Direction = ParameterDirection.Input;
                FinancialActualAmount.Value = Convert.ToDecimal(strFinancialActualAmount);
                SqlParameter Flag = new SqlParameter("@Flag", SqlDbType.NVarChar, 10);
                Flag.Direction = ParameterDirection.Input;
                Flag.Value = strFlag;
                SqlParameter UserId = new SqlParameter("@UserId", SqlDbType.UniqueIdentifier, 50);
                UserId.Direction = ParameterDirection.Input;
                UserId.Value = this.UserId;
                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;

                _Parameters = new IDataParameter[] { Id, ConferenceActualAmount, FinancialActualAmount, Flag, UserId, ReturnValue };
                string strSql = db.RunProcedureReturnString("[sp_UpdateBudgetMasterAccount]", _Parameters, out iResult);
                if (strSql == "1")
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write(strSql);
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 团号设置督导员
        /// </summary>
        private void UpdateMajorStudentGroupName()
        {
            try
            {
                int iResult = 0;
                IDataParameter[] _Parameters = new IDataParameter[] { };
                DbSql db = new DbSql();
                string strId = this.GetStringFromQueryString("id", "");
                string strGroupName = this.GetStringFromQueryString("name", "");
                string strAssistance = this.GetStringFromQueryString("assistance", "");

                SqlParameter ProductLayoutID = new SqlParameter("@ProductLayoutID", SqlDbType.UniqueIdentifier, 50);
                ProductLayoutID.Direction = ParameterDirection.Input;
                ProductLayoutID.Value = new Guid(strId);
                SqlParameter GroupName = new SqlParameter("@GroupName", SqlDbType.NVarChar, 50);
                GroupName.Direction = ParameterDirection.Input;
                GroupName.Value = strGroupName;
                SqlParameter Assistance = new SqlParameter("@Assistance", SqlDbType.UniqueIdentifier, 50);
                Assistance.Direction = ParameterDirection.Input;
                Assistance.Value = new Guid(strAssistance);
                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;

                _Parameters = new IDataParameter[] { ProductLayoutID, GroupName, Assistance, ReturnValue };
                string strSql = db.RunProcedureReturnString("sp_UpdateCrmMajorSetAssistance", _Parameters, out iResult);

                if (strSql == "1")
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write(strSql);
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 客户数据修改
        /// </summary>
        private void UpdateCrmCustomerOldUpdate(string strJson)
        {
            int iResult = 0;
            IDataParameter[] _Parameters = new IDataParameter[] { };
            DbSql db = new DbSql();
            try
            {
                CrmCustomerOld instance = (CrmCustomerOld)Globals.JSonToObject<CrmCustomerOld>(strJson);
                SqlParameter ID = new SqlParameter("@ID", SqlDbType.UniqueIdentifier, 50);
                ID.Direction = ParameterDirection.Input;
                ID.Value = instance.ID;
                SqlParameter CustomerName = new SqlParameter("@CustomerName", SqlDbType.NVarChar, 50);
                CustomerName.Direction = ParameterDirection.Input;
                CustomerName.Value = instance.CustomerName;
                SqlParameter State = new SqlParameter("@State", SqlDbType.NVarChar, 30);
                State.Direction = ParameterDirection.Input;
                State.Value = instance.State;
                SqlParameter Province = new SqlParameter("@Province", SqlDbType.NVarChar, 20);
                Province.Direction = ParameterDirection.Input;
                Province.Value = instance.Province;
                SqlParameter City = new SqlParameter("@City", SqlDbType.NVarChar, 20);
                City.Direction = ParameterDirection.Input;
                City.Value = instance.City;
                SqlParameter Area = new SqlParameter("@Area", SqlDbType.NVarChar, 20);
                Area.Direction = ParameterDirection.Input;
                Area.Value = instance.Area;
                SqlParameter Address = new SqlParameter("@Address", SqlDbType.NVarChar, 100);
                Address.Direction = ParameterDirection.Input;
                Address.Value = instance.Address;
                SqlParameter AreaId = new SqlParameter("@AreaId", SqlDbType.UniqueIdentifier, 50);
                AreaId.Direction = ParameterDirection.Input;
                AreaId.Value = instance.AreaId;
                SqlParameter AreaName = new SqlParameter("@AreaName", SqlDbType.NVarChar, 100);
                AreaName.Direction = ParameterDirection.Input;
                AreaName.Value = instance.AreaName;
                SqlParameter TradeId = new SqlParameter("@TradeId", SqlDbType.UniqueIdentifier, 50);
                TradeId.Direction = ParameterDirection.Input;
                TradeId.Value = instance.TradeId;
                SqlParameter TradeName = new SqlParameter("@TradeName", SqlDbType.NVarChar, 100);
                TradeName.Direction = ParameterDirection.Input;
                TradeName.Value = instance.TradeName;
                SqlParameter ProductId = new SqlParameter("@ProductId", SqlDbType.UniqueIdentifier, 50);
                ProductId.Direction = ParameterDirection.Input;
                ProductId.Value = instance.ProductId;
                SqlParameter ProductName = new SqlParameter("@ProductName", SqlDbType.NVarChar, 100);
                ProductName.Direction = ParameterDirection.Input;
                ProductName.Value = instance.ProductName;
                SqlParameter PersonId = new SqlParameter("@PersonId", SqlDbType.UniqueIdentifier, 50);
                PersonId.Direction = ParameterDirection.Input;
                PersonId.Value = instance.PersonId;
                SqlParameter PersonName = new SqlParameter("@PersonName", SqlDbType.NVarChar, 100);
                PersonName.Direction = ParameterDirection.Input;
                PersonName.Value = instance.PersonName;
                SqlParameter PropertyId = new SqlParameter("@PropertyId", SqlDbType.UniqueIdentifier, 50);
                PropertyId.Direction = ParameterDirection.Input;
                PropertyId.Value = instance.PropertyId;
                SqlParameter PropertyName = new SqlParameter("@PropertyName", SqlDbType.NVarChar, 100);
                PropertyName.Direction = ParameterDirection.Input;
                PropertyName.Value = instance.PropertyName;

                SqlParameter Decisionmaker = new SqlParameter("@Decisionmaker", SqlDbType.NVarChar, 30);
                Decisionmaker.Direction = ParameterDirection.Input;
                Decisionmaker.Value = instance.Decisionmaker;
                SqlParameter DecisionPosition = new SqlParameter("@DecisionPosition", SqlDbType.NVarChar, 20);
                DecisionPosition.Direction = ParameterDirection.Input;
                DecisionPosition.Value = instance.DecisionPosition;
                SqlParameter DecisionTel1 = new SqlParameter("@DecisionTel1", SqlDbType.NVarChar, 20);
                DecisionTel1.Direction = ParameterDirection.Input;
                DecisionTel1.Value = instance.DecisionTel1;
                SqlParameter DecisionTel2 = new SqlParameter("@DecisionTel2", SqlDbType.NVarChar, 20);
                DecisionTel2.Direction = ParameterDirection.Input;
                DecisionTel2.Value = instance.DecisionTel2;

                SqlParameter DecisionSex = new SqlParameter("@DecisionSex", SqlDbType.Char, 1);
                DecisionSex.Direction = ParameterDirection.Input;
                DecisionSex.Value = instance.DecisionSex;
                SqlParameter Tel1 = new SqlParameter("@Tel1", SqlDbType.NVarChar, 20);
                Tel1.Direction = ParameterDirection.Input;
                Tel1.Value = instance.Tel1;
                SqlParameter CompanyProduct = new SqlParameter("@CompanyProduct", SqlDbType.NVarChar, 100);
                CompanyProduct.Direction = ParameterDirection.Input;
                CompanyProduct.Value = instance.CompanyProduct;

                SqlParameter OperationType = new SqlParameter("@OperationType", SqlDbType.Int, 1);
                OperationType.Direction = ParameterDirection.Input;
                string strFlag = this.GetStringFromQueryString("type", "");
                if (strFlag == "0")
                {
                    OperationType.Value = 0;
                }
                else
                {
                    OperationType.Value = 1;
                }
                string strObject = this.GetStringFromQueryString("object", "");//0:保存并转到公海 1:保存
                string strCustomerCode = string.Empty;
                if (strObject == "0")
                {
                    strCustomerCode = IDMaker.GetSequenceStr("CUS001");
                }
                SqlParameter ObjectType = new SqlParameter("@ObjectType", SqlDbType.Int, 1);
                ObjectType.Direction = ParameterDirection.Input;
                ObjectType.Value = strObject;
                SqlParameter CustomerCode = new SqlParameter("@CustomerCode", SqlDbType.NVarChar, 50);
                CustomerCode.Direction = ParameterDirection.Input;
                CustomerCode.Value = strCustomerCode;
                SqlParameter AddUser = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
                AddUser.Direction = ParameterDirection.Input;
                AddUser.Value = new Guid(this.UserId.ToString());
                SqlParameter ModifyUser = new SqlParameter("@ModifyUser", SqlDbType.UniqueIdentifier, 50);
                ModifyUser.Direction = ParameterDirection.Input;
                ModifyUser.Value = new Guid(this.UserId.ToString());
                SqlParameter Explains = new SqlParameter("@Explains", SqlDbType.NVarChar, 500);
                Explains.Direction = ParameterDirection.Input;
                Explains.Value = instance.Explains;

                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;
                _Parameters = new IDataParameter[] { ID,State,Province,City,Area,Address,CustomerName,
					                        AreaId,AreaName,TradeId,TradeName,ProductId,ProductName,
                                            PersonId,PersonName,PropertyId,PropertyName,Decisionmaker,
                                            DecisionPosition,DecisionTel1,DecisionTel2,DecisionSex,Tel1,
                                            CompanyProduct,OperationType, ObjectType, CustomerCode, AddUser, 
                                            ModifyUser, Explains, ReturnValue};
                string strSql = db.RunProcedureReturnString("sp_UpateCrmCustomerOld", _Parameters, out iResult);
                if (strSql == "1")
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write(strSql);
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 废弃客户启用
        /// </summary>
        private void UpdateToCrmCustomerOld()
        {
            try
            {
                string strId = this.GetStringFromQueryString("id", "");
                string strSql = string.Format("update CrmCustomerOld set CustomerState=0 where ID='{0}'", strId);
                int iResult = bll.RunSqlCommand(strSql);
                if (iResult > 0)
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("数据更新状态为0失败!");
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 资源分配
        /// </summary>
        private void UpdateSetNegotiateTeach(string strJson)
        {
            int iResult = 0;
            IDataParameter[] _Parameters = new IDataParameter[] { };
            DbSql db = new DbSql();
            try
            {
                string[] strCustoerIds = strJson.Split(',');
                string[] strUserId = this.GetStringFromQueryString("id", "").Split(',');
                string strProlayoutId = this.GetStringFromQueryString("pid", "");
                for (int i = 0; i < strCustoerIds.Length - 1; i++)
                {
                    SqlParameter CustomerId = new SqlParameter("@CustomerId", SqlDbType.UniqueIdentifier, 50);
                    CustomerId.Direction = ParameterDirection.Input;
                    CustomerId.Value = new Guid(strCustoerIds[i].ToString());
                    SqlParameter UserId = new SqlParameter("@UserId", SqlDbType.UniqueIdentifier, 50);
                    UserId.Direction = ParameterDirection.Input;
                    UserId.Value = new Guid(strUserId[0].ToString());
                    SqlParameter ProductLayoutID = new SqlParameter("@ProductLayoutID", SqlDbType.UniqueIdentifier, 50);
                    ProductLayoutID.Direction = ParameterDirection.Input;
                    ProductLayoutID.Value = new Guid(strProlayoutId);
                    SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                    ReturnValue.Direction = ParameterDirection.Output;
                    _Parameters = new IDataParameter[] { CustomerId, UserId, ProductLayoutID, ReturnValue };
                    string strSql = db.RunProcedureReturnString("sp_UpdateCrmDeliverNegotiateTeach", _Parameters, out iResult);
                    if (strSql == "1")
                    {

                    }
                    else
                    {
                        HttpContext.Current.Response.Write(strSql);
                        return;
                    }
                }
                HttpContext.Current.Response.Write("1");
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 终端客户
        /// </summary>
        private void UpdateCrmCustomerOldStop()
        {
            try
            {
                string strId = this.GetStringFromQueryString("id", "");
                string strSql = string.Format("update CrmCustomerOld set CustomerState=3 where ID='{0}'", strId);
                int iResult = bll.RunSqlCommand(strSql);
                if (iResult > 0)
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("数据更新状态为3失败!");
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 启用客户
        /// </summary>
        private void UpdateCrmCustomerStop()
        {
            try
            {
                string strCustomerId = this.GetStringFromQueryString("id", "");
                int iResult = 0;
                IDataParameter[] _Parameters = new IDataParameter[] { };
                DbSql db = new DbSql();
                SqlParameter CustomerId = new SqlParameter("@CustomerId", SqlDbType.UniqueIdentifier, 50);
                CustomerId.Direction = ParameterDirection.Input;
                CustomerId.Value = new Guid(strCustomerId);
                SqlParameter Type = new SqlParameter("@Type", SqlDbType.Int, 1);
                Type.Direction = ParameterDirection.Input;
                Type.Value = 0;
                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;

                _Parameters = new IDataParameter[] { CustomerId, Type, ReturnValue };
                string strSql = db.RunProcedureReturnString("sp_EditCrmCustomerStop", _Parameters, out iResult);
                if (strSql == "1")
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write(strSql);
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }



        /// <summary>
        /// 自定义保存方法，执行存储过程
        /// </summary>
        /// <param name="strEntity">实体</param>
        /// <param name="strJson">JSON数据</param>
        /// <param name="strAction">动作</param>
        private void RunProcedure(string strEntity, string strJson, string strAction)
        {
            BaseBussnies blls = new BaseBussnies();
            BTCrmCustomer bt = new BTCrmCustomer();
            CrmCustomerReturn instanceReturn = new CrmCustomerReturn();
            try
            {
                string strSql = "";
                int iResult = 0;
                if (strAction == "procedure")
                {
                    #region ------ CrmUserMove(员工异动) ------
                    if (strEntity == "CrmUserMove")
                    {
                        CrmUserMove instance = Globals.JSonToObject<CrmUserMove>(strJson);
                        Globals.SetPropertyValue(instance, "AddUser", this.UserId);
                        Globals.SetPropertyValue(instance, "AddTime", System.DateTime.Now);
                        //数据验证
                        string strMsg = instance.CheckData();
                        if (strMsg != "")
                        {
                            HttpContext.Current.Response.Write(strMsg);
                            return;
                        }
                        strSql = string.Format("Exec sp_CrmUserMove '{0}','{1}','{2}','{3}'",
                                            instance.MoverUserID, instance.MoveDate, instance.Explain, instance.AddUser);
                    }
                    #endregion
                    #region ------ CrmLinkMan(添加联系人)  ------
                    else if (strEntity == "CrmLinkMan")
                    {
                        var list = (List<CrmLinkMan>)Globals.JSonToObject<List<CrmLinkMan>>(strJson);
                        foreach (var v in list)
                        {
                            Globals.SetPropertyValue(v, "AddUser", this.UserId);
                            Globals.SetPropertyValue(v, "AddTime", System.DateTime.Now);
                            string strSqls = string.Format("Exec sp_AddCrmLinkMan '{0}','{1}','{2}','{3}','{4}','{5}','{6}'," +
                                                "'{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}'",
                                                    v.ID, ZX.BLL.IDMaker.GetSequenceStr("CUS002"), v.Caption, v.CustomId,
                                                    v.TypeID, v.Sex, v.Position, v.DeptName, v.MobileTel, v.Email,
                                                    v.Homeplace, v.BirthdayType, v.Birthday, v.LinkManFancy, v.EXP3, v.EXP4, v.Drink,
                                                    "00000000-0000-0000-0000-000000000000", v.AddUser, v.AddTime, 0);
                            int iResults = bll.RunSqlCommand(strSqls);
                            if (iResults > 0)
                            {
                            }
                            else
                            {
                                HttpContext.Current.Response.Write("0");
                                return;
                            }
                        }
                        HttpContext.Current.Response.Write("1");
                        return;
                    }
                    #endregion
                    #region ------ CrmActivity(添加联系记录) ------
                    else if (strEntity == "CrmActivity")
                    {
                        var list = (List<CrmActivity>)Globals.JSonToObject<List<CrmActivity>>(strJson);
                        foreach (var v in list)
                        {
                            Globals.SetPropertyValue(v, "AddUser", this.UserId);
                            Globals.SetPropertyValue(v, "AddTime", System.DateTime.Now);
                            if (v.PlanStartDate.ToString() == "0001-1-1 0:00:00")
                            {
                                v.PlanStartDate = DateTime.Now;
                            }
                            if (v.PlanEndDate.ToString() == "0001-1-1 0:00:00")
                            {
                                v.PlanEndDate = DateTime.Now;
                            }
                            string strSqls = string.Format("Exec sp_AddCrmActivity '{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}'",
                                                v.ID, ZX.BLL.IDMaker.GetSequenceStr("CUS003"), v.Caption, v.CustomId, v.TypeId, v.LinkManID, v.PlanStartDate,
                                                v.PlanEndDate, v.Contents, v.Explain, v.AddUser,
                                                v.AddTime, "", "");
                            int iResults = bll.RunSqlCommand(strSqls);
                            if (iResults > 0)
                            {
                            }
                            else
                            {
                                HttpContext.Current.Response.Write("0");
                                return;
                            }
                        }
                        HttpContext.Current.Response.Write("1");
                        return;
                    }
                    #endregion
                    #region ------ CrmActivityCall(添加拜访记录) ------
                    else if (strEntity == "CrmActivityCall")
                    {
                        var list = (List<CrmActivity>)Globals.JSonToObject<List<CrmActivity>>(strJson);
                        foreach (var v in list)
                        {
                            Globals.SetPropertyValue(v, "AddUser", this.UserId);
                            Globals.SetPropertyValue(v, "AddTime", System.DateTime.Now);
                            if (v.PlanStartDate.ToString() == "0001-1-1 0:00:00")
                            {
                                v.PlanStartDate = DateTime.Now;
                            }
                            if (v.PlanEndDate.ToString() == "0001-1-1 0:00:00")
                            {
                                v.PlanEndDate = DateTime.Now;
                            }
                            string strSqls = string.Format("Exec sp_AddCrmActivityCall '{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}'",
                                                v.ID, ZX.BLL.IDMaker.GetSequenceStr("CUS003"), v.Suject, v.CustomId, v.TypeId, v.LinkManID, v.PlanStartDate,
                                                v.PlanEndDate, v.AnticipeResult, v.Contents, v.Result, v.Explain, v.AddUser,
                                                v.AddTime, v.AddUser, v.AddTime);
                            int iResults = bll.RunSqlCommand(strSqls);
                            if (iResults > 0)
                            {
                            }
                            else
                            {
                                HttpContext.Current.Response.Write("0");
                                return;
                            }
                        }
                        HttpContext.Current.Response.Write("1");
                        return;
                    }
                    #endregion
                    #region --- CrmPrivateCustom(公海转私海) ----
                    else if (strEntity == "CrmPrivateCustom")
                    {
                        strJson = this.GetStringFromQueryString("id", "");
                        if (bll.GetCrmCustomerPublic(new Guid(strJson)))
                        {
                            if (bll.GetCrmCustomerPrivate(new Guid(strJson)))
                            {
                                //该客户已是私海客户!请即使刷新页面!
                                HttpContext.Current.Response.Write("该客户已是私海客户!");
                                return;
                            }
                            else
                            {
                                DbSql db = new DbSql();
                                int iCount = db.GetRowCount("V_CrmPrivateCustom", " AddUser='" + this.UserId + "' and CustomUser='" + this.UserId + "'");

                                int iAllCount = 0;
                                //从列表中单独设置的个数
                                iAllCount = bt.GetPrivateNumBySet(this.UserId.ToString());
                                if (iAllCount<1)
                                {
                                   iAllCount= bt.GetPrivateNum("PrivateAreaTotalSet");
                                }
                                if (iCount >= iAllCount)
                                {
                                    //您的私海客户数已达到设置的私海总数,如有疑问请联系管理员!
                                    HttpContext.Current.Response.Write("您的私海客户数已达到设置的私海总数,如有疑问请联系管理员!");
                                    return;
                                }
                                else
                                {
                                    strSql = string.Format("Exec sp_EditCrmCustomerToPrivate '{0}','{1}','{2}','{3}'",
                                                strJson, this.UserId, 0, "00000000-0000-0000-0000-000000000000");
                                }
                            }
                        }
                        else
                        {
                            HttpContext.Current.Response.Write("该客户不是公海客户,不能进行当前操作,请即时刷新数据!");
                            return;
                        }
                    }
                    #endregion
                    #region ---- CrmWillCustomer(公海转意向客户) ----
                    else if (strEntity == "CrmWillCustomer")
                    {
                        strJson = this.GetStringFromQueryString("id", "");
                        if (bll.GetCrmCustomerPublic(new Guid(strJson)))
                        {
                            if (bt.IsExistWillCustomer(new Guid(strJson), new Guid(this.UserId.ToString())))
                            {
                                //该客户已是意向客户!
                                HttpContext.Current.Response.Write("该客户已是意向客户!");
                                return;
                            }
                            else
                            {
                                strSql = string.Format("Exec sp_EditCrmCustomerToWill '{0}','{1}'", strJson, this.UserId);
                            }
                        }
                        else
                        {
                            HttpContext.Current.Response.Write("该客户不是公海客户,不能进行当前操作,请即时刷新数据!");
                            return;
                        }
                    }
                    #endregion
                    #region ---- CrmWillCustomer(公海转意向客户) ----
                    else if (strEntity == "CrmWillCustomers")
                    {
                        //this.UserId 
                        string strCurrentUserId = this.GetStringFromQueryString("uId", "");
                        strJson = this.GetStringFromQueryString("id", "");
                        if (bll.GetCrmCustomerPublic(new Guid(strJson)))
                        {

                            iResult = 0;
                            IDataParameter[] _Parameters = new IDataParameter[] { };
                            DbSql db = new DbSql();
                            SqlParameter CustomerID = new SqlParameter("@CustomerID", SqlDbType.UniqueIdentifier, 50);
                            CustomerID.Direction = ParameterDirection.Input;
                            CustomerID.Value = new Guid(strJson);
                            SqlParameter AddUser = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
                            AddUser.Direction = ParameterDirection.Input;
                            AddUser.Value = new Guid(strCurrentUserId);
                            SqlParameter FromUser = new SqlParameter("@FromUser", SqlDbType.UniqueIdentifier, 20);
                            FromUser.Direction = ParameterDirection.Input;
                            FromUser.Value = this.UserId;
                            SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                            ReturnValue.Direction = ParameterDirection.Output;
                            _Parameters = new IDataParameter[] { CustomerID, AddUser, FromUser, ReturnValue };
                            strSql = db.RunProcedureReturnString("sp_EditCrmCustomerToWill", _Parameters, out iResult);
                            if (strSql == "1")
                            {
                                HttpContext.Current.Response.Write("1");
                            }
                            else
                            {
                                HttpContext.Current.Response.Write(strSql);
                            }
                            return;
                            //if (bt.IsExistWillCustomer(new Guid(strJson), new Guid(this.UserId.ToString())))
                            //{
                            //    //该客户已是意向客户!
                            //    HttpContext.Current.Response.Write("该客户已是意向客户!");
                            //    return;
                            //}
                            //else
                            //{
                            //    string strCurrentUserId=this.GetStringFromQueryString("uId","");
                            //    strSql = string.Format("Exec sp_EditCrmCustomerToWill '{0}','{1}'", strJson, new Guid(strCurrentUserId));
                            //}
                        }
                        else
                        {
                            HttpContext.Current.Response.Write("该客户不是公海客户,不能进行当前操作,请即时刷新数据!");
                            return;
                        }
                    }
                    #endregion
                    #region---- CrmPublicCustom(意向客户转向公海) ----
                    else if (strEntity == "CrmWillCustomToPublic")
                    {
                        string strCustomerId = this.GetStringFromQueryString("cid", "");
                        if (bll.GetCrmCustomerIsWill(new Guid(strCustomerId)))
                        {
                            strJson = this.GetStringFromQueryString("id", "");
                            strSql = string.Format("Exec sp_EditCrmCustomerToPublic '{0}','{1}','{2}','{3}'", strJson, this.UserId, strCustomerId, 0);
                        }
                        else
                        {
                            HttpContext.Current.Response.Write("该客户已不是意向客户，请及时刷新数据!");
                            return;
                        }
                    }
                    #endregion
                    #region ---- CrmPrivateCustom(意向客户转向私海) ----
                    else if (strEntity == "CrmWillCustomToPrivate")
                    {
                        string strCustomerId = this.GetStringFromQueryString("cid", "");
                        if (bll.GetCrmCustomerIsWill(new Guid(strCustomerId)))
                        {
                            if (bll.GetCrmCustomerPrivate(new Guid(strCustomerId)))
                            {
                                HttpContext.Current.Response.Write("该客户已是私海客户,请即时刷新数据!");
                                return;
                            }
                            else
                            {
                                strJson = this.GetStringFromQueryString("id", "");
                                DbSql db = new DbSql();
                                int iCount = db.GetRowCount("CrmPrivateCustom", " AddUser='" + this.UserId + "' and CustomUser='" + this.UserId + "'");
                               
                                //int iAllCount = bt.GetPrivateNum("PrivateAreaTotalSet");
                                //if (iCount >= iAllCount)
                                int iAllCount = 0;
                                //从列表中单独设置的个数
                                iAllCount = bt.GetPrivateNumBySet(this.UserId.ToString());
                                if (iAllCount < 1)
                                {
                                    iAllCount = bt.GetPrivateNum("PrivateAreaTotalSet");
                                }
                                if (iCount >= iAllCount)
                                {
                                    HttpContext.Current.Response.Write("您的私海客户数已达到设置的私海总数,如有疑问请联系管理员!");
                                    return;
                                }
                                else
                                {
                                    strSql = string.Format("Exec sp_EditCrmCustomerToPrivate '{0}','{1}','{2}','{3}'",
                                                strCustomerId, this.UserId, 1, strJson);
                                }
                            }
                        }
                        else
                        {
                            HttpContext.Current.Response.Write("该客户已不是意向客户，请及时刷新数据!");
                            return;
                        }
                    }
                    #endregion
                    #region ------- CrmCustomerAttach(添加附件) -------
                    else if (strEntity == "CrmCustomerAttach")
                    {
                        CrmCustomerAttach instance = Globals.JSonToObject<CrmCustomerAttach>(strJson);
                        Globals.SetPropertyValue(instance, "AddUser", this.UserId);
                        Globals.SetPropertyValue(instance, "AddTime", System.DateTime.Now);
                        Globals.SetPropertyValue(instance, "ID", Guid.NewGuid());
                        string strCustomerId = this.GetStringFromQueryString("id", "");
                        strSql = string.Format("Exec sp_AddCrmCustomerAttach '{0}','{1}','{2}','{3}','{4}','{5}','{6}'",
                                    instance.ID, strCustomerId, instance.Caption, instance.Size,
                                    instance.Address, instance.Explain, instance.AddUser);
                    }
                    #endregion
                    #region------ CrmCustomerInfo(客户分配保存一条数据至私海) ---
                    else if (strEntity == "CrmCustomerInfo")
                    {
                        strJson = this.GetStringFromQueryString("id", ""); //客户ID
                        string strMrg = this.GetStringFromQueryString("mrg", "");//客户经理ID
                        if (strMrg != "")
                        {
                            strSql = string.Format("Exec sp_AddCrmCustomerInfoToPrivate '{0}','{1}','{2}','{3}','{4}'", strJson, strMrg,
                                                "客户经理录入客户", this.UserId, DateTime.Now);
                        }
                        else
                        {
                            strSql = string.Format("Exec sp_AddCrmCustomerInfoToPrivate '{0}','{1}','{2}','{3}','{4}'", strJson, this.UserId,
                                                "客户分配时插入的对应客户数据", this.UserId, DateTime.Now);
                        }
                        
                    }
                    #endregion
                    #region-------------- CrmCustomerReturn(退回) --------------
                    else if (strEntity == "CrmCustomerReturn")
                    {
                        instanceReturn = Globals.JSonToObject<CrmCustomerReturn>(strJson);
                        Globals.SetPropertyValue(instanceReturn, "AddUser", this.UserId);
                        Globals.SetPropertyValue(instanceReturn, "AddTime", System.DateTime.Now);
                        Globals.SetPropertyValue(instanceReturn, "ModifyUser", "00000000-0000-0000-0000-000000000000");
                        Globals.SetPropertyValue(instanceReturn, "ModifyTime", "1900-01-01");
                        if (bll.GetCrmCustomerIsReturn(instanceReturn.CustomerId))
                        {
                            //该客户已退回!请即使刷新页面!
                            HttpContext.Current.Response.Write("该客户已退回!");
                            return;
                        }
                        else
                        {
                            strSql = string.Format("Exec sp_AddCrmCustomerReturn '{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}'",
                                            instanceReturn.CustomerId, instanceReturn.ReciveUser, instanceReturn.CustomerState,
                                            instanceReturn.ReturnReason, instanceReturn.AddUser, instanceReturn.AddTime,
                                            instanceReturn.ModifyUser, instanceReturn.ModifyTime);
                        }
                    }
                    #endregion
                    #region------- (CrmCustomerReady)公海转准备客户 -------
                    else if (strEntity == "CrmCustomerReady")
                    {
                        strJson = this.GetStringFromQueryString("id", "");//客户ID
                        if (bll.GetCrmCustomerPublic(new Guid(strJson)))
                        {
                            if (bt.IsExistReadyCustomer(new Guid(strJson), new Guid(this.UserId.ToString())))
                            {
                                //该客户已是准备客户!
                                HttpContext.Current.Response.Write("该客户已是准备客户,请即时刷新数据!");
                                return;
                            }
                            else
                            {
                                strSql = string.Format("Exec sp_EditCrmCustomerToReady '{0}','{1}'", strJson, this.UserId);
                            }
                        }
                        else
                        {
                            HttpContext.Current.Response.Write("该客户不是公海客户,不能进行当前操作,请即时刷新数据!");
                            return;
                        }
                    }
                    #endregion
                    #region------- (CrmCustomerReadyToPrivate)准备客户转私海 -------
                    else if (strEntity == "CrmCustomerReadyToPrivate")
                    {
                        string strCustomerId = this.GetStringFromQueryString("cid", "");
                        if (bll.GetCrmCustomerIsReady(new Guid(strCustomerId)))
                        {
                            if (bll.GetCrmCustomerPrivate(new Guid(strCustomerId)))
                            {
                                //该客户已是私海客户!请即使刷新页面!
                                HttpContext.Current.Response.Write("该客户已是私海客户,请即时刷新数据!");
                                return;
                            }
                            else
                            {
                                strJson = this.GetStringFromQueryString("id", "");
                                DbSql db = new DbSql();
                                int iCount = db.GetRowCount("CrmPrivateCustom", " AddUser='" + this.UserId + "' and CustomUser='" + this.UserId + "'");
                                //int iAllCount = bt.GetPrivateNum("PrivateAreaTotalSet");
                                //if (iCount >= iAllCount)
                                int iAllCount = 0;
                                //从列表中单独设置的个数
                                iAllCount = bt.GetPrivateNumBySet(this.UserId.ToString());
                                if (iAllCount < 1)
                                {
                                    iAllCount = bt.GetPrivateNum("PrivateAreaTotalSet");
                                }
                                if (iCount >= iAllCount)
                                {
                                    HttpContext.Current.Response.Write("您的私海客户数已达到设置的私海总数,如有疑问请联系管理员!");
                                    return;
                                }
                                else
                                {
                                    strSql = string.Format("Exec sp_EditCrmCustomerToPrivate '{0}','{1}','{2}','{3}'",
                                                strCustomerId, this.UserId, 2, strJson);
                                }
                            }
                        }
                        else
                        {
                            HttpContext.Current.Response.Write("该客户已不是准备客户，请及时刷新数据!");
                            return;
                        }
                    }
                    #endregion
                    #region------- (CrmCustomerReadyToPublic)准备客户转公海 -------
                    else if (strEntity == "CrmCustomerReadyToPublic")
                    {
                        string strCustomerId = this.GetStringFromQueryString("cid", "");
                        if (bll.GetCrmCustomerIsReady(new Guid(strCustomerId)))
                        {
                            strJson = this.GetStringFromQueryString("id", "");
                            strSql = string.Format("Exec sp_EditCrmCustomerToPublic '{0}','{1}','{2}','{3}'", strJson, this.UserId, strCustomerId, 1);
                        }
                        else
                        {
                            HttpContext.Current.Response.Write("该客户已不是准备客户，请及时刷新数据!");
                            return;
                        }
                    }
                    #endregion
                    #region------- CrmCustomerPublic(约场订单报废后将客户转公海) -------
                    else if (strEntity == "CrmCustomerPublic")
                    {
                        string strCustomerId = this.GetStringFromQueryString("cid", "");
                        if (bll.GetCrmCustomerBaoFei(new Guid(strCustomerId)))
                        {
                            strJson = "00000000-0000-0000-0000-000000000000";
                            strSql = string.Format("Exec sp_EditCrmCustomerToPublic '{0}','{1}','{2}','{3}'", strJson, this.UserId, strCustomerId, 2);
                        }
                        else
                        {
                            HttpContext.Current.Response.Write("该客户状态不为报废状态,不能操作!");
                            return;
                        }
                    }
                    #endregion

                    iResult = blls.RunSqlCommand(strSql);
                    if (iResult > 0)
                    {
                        if (strEntity == "CrmCustomerReturn")
                        {   
                            string strCustomerId = this.GetStringFromQueryString("cid", "");
                            string strReturn = this.ReturnSaveMsg("客户退回", "【退回客户】" + GetCustomerName(strCustomerId==""?Guid.Empty:new Guid(strCustomerId),0) + "!", instanceReturn.AddUser, instanceReturn.ReciveUser);
                        }
                        HttpContext.Current.Response.Write("1");
                    }
                    else
                    {
                        HttpContext.Current.Response.Write("0");
                    }
                }
                else
                {
                    HttpContext.Current.Response.Write("0");
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }


        /// <summary>
        /// 退回时保存消息
        /// </summary>
        /// <returns></returns>
        private string ReturnSaveMsg(string msgTitle, string msgContent, Guid sendUser, Guid receiverUser)
        {
            try
            {
                BDatMessageQueue target = new BDatMessageQueue(); // TODO: 初始化为适当的值
                DatMessageQueue msg = DatMessageQueue.New(); // TODO: 初始化为适当的值
                msg.MsgID = Guid.NewGuid();
                msg.Title = msgTitle.ToString();
                //msg.MsgTemplate = "";
                msg.MsgContent = msgContent.ToString();
                msg.MessageType = "0";
                msg.ExpectTime = DateTime.Now;
                msg.AddUser = sendUser;
                msg.PushTime = DateTime.Now;
                //msg.QueryID = new Guid("F8ED27B4-B5BC-4497-9881-FE3AD0512125");//关联信息来源的编号

                IList<DatMessageReceiver> MessageReceiver = new List<DatMessageReceiver>(); // TODO: 初始化为适当的值
                DatMessageReceiver mr1 = DatMessageReceiver.New();
                mr1.MsItemID = Guid.NewGuid();
                mr1.MsgID = msg.MsgID;
                mr1.ReceiverID = receiverUser;
                mr1.ReceiverType = "U";
                MessageReceiver.Add(mr1);
                target.AddMessage(msg, MessageReceiver);
                BDatMessageQueue target1 = new BDatMessageQueue(); // TODO: 初始化为适当的值
                DateTime CurrentTime = DateTime.Now; // TODO: 初始化为适当的值
                target1.PushMessages(CurrentTime);
                return "1";
            }
            catch
            {
                return "0";
            }
        }

        /// <summary>
        /// 自定义查看方法
        /// </summary>
        /// <param name="strEntity">实体</param>
        /// <param name="strJson">JSON数据</param>
        private void RunCheck(string strEntity, string strJson)
        {
            switch (strEntity)
            {
                case "CustomerName":
                    CheckCustomerNameIsExists(strJson);
                    break;
                case "CustomerTel":
                    CheckCustomerTelIsExists(strJson);
                    break;
                case "CrmLinkTel":
                    CheckLinkManTelIsExists(strJson);
                    break;
                case "CrmCustomer":
                    LoadCustomerName(strJson);
                    break;
                case "CrmCustomerCheck":
                    CheckCustomerIsPrevateState(strJson);
                    break;
                case "CrmCustomerCheckField":
                    CheckCrmCustomerOrder(strJson);
                    break;
                case "CrmCustomerInfoCheckField":
                    CheckCrmCustomerInfoCheckField(strJson);
                    break;
                case "V_DatEmployeeForUser":
                    SelectDatEmployeeByDeptId(strJson);
                    break;
                case "V_DatEmployeeForName":
                    SelectDatEmployeeByName(strJson);
                    break;
                case "CrmCustomerReturn":
                    CheckCrmCustomerReturn(strJson);
                    return;
                case "CrmCustomerOrderAgree":
                    WorkFlowCrmCustomerOrderAgree(strJson);
                    break;
                case "CrmValueAgreeS":
                    WorkFlowCrmValueAgreeS(strJson);
                    break;
                case "CrmValueAgreeT":
                    WorkFlowCrmValueAgreeT(strJson);
                    break;
                case "CrmCustomerOrderAgrees":
                    WorkFlowCrmCustomerOrderAgrees(strJson);
                    break;
                case "CrmCustomerOrderUnAgree":
                    WorkFlowCrmCustomerOrderUnAgree(strJson);
                    break;
                case "CrmDeliverMajorUnAgree":
                    WorkFlowCrmDeliverMajorUnAgree(strJson);
                    break;
                case "CrmDeliverTrainUnAgree":
                    WorkFlowCrmDeliverTrainUnAgree(strJson);
                    break;
                case "CrmDeliverHrUnAgree":
                    WorkFlowCrmDeliverHrUnAgree(strJson);
                    break;
                case "CrmDeliverProjectUnAgree":
                    WorkFlowCrmDeliverProjectUnAgree(strJson);
                    break;
                case "CrmValueUnAgree":
                    WorkFlowCrmValueUnAgree(strJson);
                    break;
                case "DatUser":
                    CheckDatUserByUName(strJson);
                    break;
                case "CheckCustomerOrder":
                    CheckCustomerOrder(strJson);
                    break;
                case "CrmCustomerOrderOK":
                    CheckCrmCustomerOrderOK(strJson);
                    break;
                case "CrmDeliverMajorPayAccount":
                    CheckCrmDeliverMajorPayAccount(strJson);
                    break;
                case "CrmDeliverHrPayAccount":
                    CheckCrmDeliverHrPayAccount(strJson);
                    break;
                case "CrmCustomerInfoID":
                    CheckCrmCustomerInfoID(strJson);
                    break;
                case "CrmProductLayout":
                    CheckCrmProductLayout();
                    break;
                case "MajorStudentDeptName":
                    CheckMajorStudentDeptName();
                    break;
                case "MajorStudentCustomerMgrName":
                    CheckMajorStudentCustomerMgrName();
                    break;
                case "MajorStudentGroupName":
                    CheckMajorStudentGroupName();
                    break;
                case "MajorStudentDataList":
                    CheckMajorStudentDataList();
                    break;
                case "MajorStudentSignCount":
                    CheckMajorStudentSignCount();
                    break;
                case "CheckCrmDeliverMajorInfo":
                    CheckCrmDeliverMajorInfoByCustomerId();
                    break;
                case "CheckCustomerOld":
                    CheckCustomerOldIsExists();
                    break;
                case "ProductCode":
                    GetProductCode();
                    break;
                case "CrmCommisionExtend":
                    UpdateCrmCommisionInfo_YituiBargain(strJson);
                    break;
                case　"CrmCustomerChannel":
                    CheckCrmCustomerChannelUngree();
                    break;
                case "CrmActivityRecord":
                    CheckCrmActivityRecord();
                    break;
                case "CrmCustomerAddTime":
                    CheckCrmCustomerAddTime();
                    break;
                case "CrmValueCount":
                    CheckCrmValueCount();
                    break;
                default:
                    break;
            }
        }
        /// <summary>
        /// 保存客户信息时检查客户数据
        /// </summary>
        /// <param name="strEntity">实体</param>
        /// <param name="strJson">JSON数据</param>
        private void CheckCustomerNameIsExists(string strJson)
        {
            try
            {
                strJson = this.GetStringFromQueryString("id", "");
                string strFlag = this.GetStringFromQueryString("temp", "");
                string strName = this.GetStringFromQueryString("name", "");
                string[] strValue = strName.Split(',');
                if (strValue.Length >= 1)
                {
                    if (strValue.Length == 1)  //单击检查按钮
                    {
                        #region ================验证客户名================
                        //检查公海表(CrmCustomer)中客户信息
                        if (bll.CrmCustomerNameIsExists(new Guid(strJson), strFlag, strValue[0]))
                        {
                            HttpContext.Current.Response.Write("1");  //客户名已存在
                            return;
                        }
                        //检查CrmCustomerInfo表中客户信息
                        if (bll.CrmCustomerInfoNameIsExists(new Guid(strJson), strFlag, strValue[0]))
                        {
                            HttpContext.Current.Response.Write("11");  //CrmCustomerInfo表客户名已存在
                            return;
                        }

                        int lengthName = 0;
                        string iLength = System.Configuration.ConfigurationManager.AppSettings["ValidationCustomerName"].ToString();
                        if (iLength == "")
                        {
                            lengthName = 8;
                        }
                        else
                        {
                            lengthName = int.Parse(iLength);
                        }
                        if (strValue[0].Length >= lengthName)  //客户名的长度大于4小于8
                        {
                            if (bll.CrmCustomerNameIsExistsLikeName(new Guid(strJson), strFlag, strValue[0].Substring(4, 4)))
                            {
                                HttpContext.Current.Response.Write("111");
                                return;
                            }
                            else
                            {
                                if (bll.CrmCustomerInfoNameIsExistsLikeName(new Guid(strJson), strFlag, strValue[0].Substring(4, 4)))
                                {
                                    HttpContext.Current.Response.Write("1111");
                                    return;
                                }
                            }
                        }
                        HttpContext.Current.Response.Write("100");  //客户名不存在
                        #endregion
                    }
                    else if (strValue.Length >= 3)  //保存时自动检查
                    {
                        if (strFlag == "1") //新增检查
                        {
                            string startTime = DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00.000";
                            string endTime = DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:00.000";
                            string userId = this.UserId.ToString();
                            int iSetCustomerCount = bll.GetPrivateNum("InsertCustomerTotal");
                            int iAllCustomerCount = bll.GetCrmCustomerCount(new Guid(userId), startTime, endTime);
                            if (iAllCustomerCount >= iSetCustomerCount)
                            {
                                HttpContext.Current.Response.Write("5");  //当前用户添加的客户数超过设置的客户总数
                            }
                            else
                            {
                                DataCheck(strJson, strFlag, strValue);
                            }
                        }
                        else
                        {
                            DataCheck(strJson, strFlag, strValue);
                        }
                    }
                }
                else
                {
                    HttpContext.Current.Response.Write("0");
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);  //异常
            }
        }
        private void DataCheck(string strJson, string strFlag, string[] strValue)
        {
            int lengthName = 0;
            string iLength = "8";

            #region ================验证客户名================
            //检查(CrmCustomer)中客户名称
            if (bll.CrmCustomerNameIsExists(new Guid(strJson), strFlag, strValue[0]))
            {
                HttpContext.Current.Response.Write("1");  //客户名已存在
                return;
            }
            //检查(CrmCustomerInfo)表中客户名称
            if (bll.CrmCustomerInfoNameIsExists(new Guid(strJson), strFlag, strValue[0]))
            {
                HttpContext.Current.Response.Write("11");  //客户名已存在
                return;
            }
            #endregion

            #region ================验证手机================
            //决策人手机
            int iTel = bll.SaveCrmCustomerTelIsExists(new Guid(strJson), strFlag, strValue[2]);
            if (iTel == 1)
            {
                HttpContext.Current.Response.Write("2");  //手机1已存在 CrmCustomer
                return;
            }
            else if (iTel == 2)
            {
                HttpContext.Current.Response.Write("22");  //手机2已存在 CrmCustomer
                return;
            }
            else if (iTel == 3)
            {
                HttpContext.Current.Response.Write("222");  //手机1已存在 CrmCustomerInfo
                return;
            }
            else if (iTel == 4)
            {
                HttpContext.Current.Response.Write("2222");  //手机2已存在 CrmCustomerInfo
                return;
            }
            if (strValue[3] != "")
            {
                int iTel1 = bll.SaveCrmCustomerTelIsExists(new Guid(strJson), strFlag, strValue[3]);
                if (iTel1 == 1)
                {
                    HttpContext.Current.Response.Write("3");  //手机1已存在 CrmCustomer
                    return;
                }
                else if (iTel1 == 2)
                {
                    HttpContext.Current.Response.Write("33");  //手机2已存在 CrmCustomer
                    return;
                }
                else if (iTel1 == 3)
                {
                    HttpContext.Current.Response.Write("333");  //手机1已存在 CrmCustomerInfo
                    return;
                }
                else if (iTel1 == 4)
                {
                    HttpContext.Current.Response.Write("3333");  //手机2已存在 CrmCustomerInfo
                    return;
                }
            }
            #endregion

            iLength = System.Configuration.ConfigurationManager.AppSettings["ValidationCustomerName"].ToString();
            if (iLength == "")
            {
                lengthName = 8;
            }
            else
            {
                lengthName = int.Parse(iLength);
            }
            if (strValue[0].Length >= lengthName)  //客户名的长度大于4小于8
            {
                if (bll.CrmCustomerNameIsExistsLikeName(new Guid(strJson), strFlag, strValue[0].Substring(4, 4)))
                {
                    HttpContext.Current.Response.Write("111");
                    return;
                }
                else
                {
                    if (bll.CrmCustomerInfoNameIsExistsLikeName(new Guid(strJson), strFlag, strValue[0].Substring(4, 4)))
                    {
                        HttpContext.Current.Response.Write("1111");
                        return;
                    }
                }
            }
            HttpContext.Current.Response.Write("100");  //验证通过
        }
        /// <summary>
        /// 检查联系人手机是否已存在
        /// </summary>
        /// <param name="strJson"></param>
        private void CheckLinkManTelIsExists(string strJson)
        {
            try
            {
                strJson = this.GetStringFromQueryString("id", "");
                string strFlag = this.GetStringFromQueryString("temp", "");
                string strTel = this.GetStringFromQueryString("tel", "");
                string strCid = GetStringFromQueryString("cid", "");
                string strName = GetStringFromQueryString("cname", "");
                if (bll.CrmLinkManNameIsExists(strJson, strFlag, strCid, strName.Trim()))
                {
                    //已存在
                    HttpContext.Current.Response.Write("2");
                }
                else
                {
                    //决策人和决策人手机已存在
                    if (bll.CrmLinkManTelIsExists(strJson, strFlag, strTel))
                    {
                        HttpContext.Current.Response.Write("1");  //联系人手机已存在
                    }
                    else
                    {
                        HttpContext.Current.Response.Write("3");  //联系人手机不存在
                    }
                }
            }
            catch (Exception e)
            {
                HttpContext.Current.Response.Write(e);  //异常
            }
        }
        /// <summary>
        /// 检查决策人手机是否已存在
        /// </summary>
        /// <param name="strJson"></param>
        private void CheckCustomerTelIsExists(string strJson)
        {
            try
            {
                strJson = this.GetStringFromQueryString("id", "");
                string strFlag = this.GetStringFromQueryString("temp", "");
                string strName = this.GetStringFromQueryString("name", "");
                //决策人手机(CrmCustomer)
                int iTelCustomer = bll.CrmCustomerTelIsExists(new Guid(strJson), strFlag, strName);
                if (iTelCustomer == 1)
                {
                    HttpContext.Current.Response.Write("1");  //决策人手机1已存在
                    return;
                }
                else if (iTelCustomer == 2)
                {
                    HttpContext.Current.Response.Write("2");  //决策人手机2已存在
                    return;
                }
                else
                {
                    //决策人手机(CrmCustomerInfo)
                    int iTelCustomerInfo = bll.CrmCustomerInfoTelIsExists(new Guid(strJson), strFlag, strName);
                    if (iTelCustomerInfo == 1)
                    {
                        HttpContext.Current.Response.Write("11");  //决策人手机1已存在
                        return;
                    }
                    else if (iTelCustomerInfo == 2)
                    {
                        HttpContext.Current.Response.Write("22");  //决策人手机2已存在
                        return;
                    }
                    else
                    {
                        HttpContext.Current.Response.Write("100");  //决策人手机正常
                    }
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);  //异常
            }
        }
        /// <summary>
        /// 联想获取用户名
        /// </summary>
        /// <param name="strJson">JSON数据</param>
        private void LoadCustomerName(string strJson)
        {
            IList<BaseEntity> listCustomerName = new List<BaseEntity>();
            DbSql db = new DbSql();
            string strSql = string.Format("select ID as id,CustomerName as fname from CrmCustomer where CustomerName like '%{0}%'", strJson);
            DataTable dt = db.ExecuteQuery(strSql);
            string str = Globals.DataTableToJSON(dt);
            HttpContext.Current.Response.Write(str);
        }
        /// <summary>
        /// 开始按钮事件前判断当前客户数据是否可进行相应操作
        /// </summary>
        /// <param name="strJson"></param>
        private void CheckCustomerIsPrevateState(string strJson)
        {
            try
            {
                strJson = this.GetStringFromQueryString("id", "");
                if (strJson == "0")  //点击新增时检查是否还可以添加客户
                {
                    string startTime = DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00.000";
                    string endTime = DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:00.000";
                    string userId = this.UserId.ToString();
                    int iSetCustomerCount = bll.GetPrivateNum("InsertCustomerTotal");
                    int iAllCustomerCount = bll.GetCrmCustomerCount(new Guid(userId), startTime, endTime);
                    if (iAllCustomerCount >= iSetCustomerCount)
                    {
                        HttpContext.Current.Response.Write("当前用户添加的客户数超过设置的客户总数!");
                    }
                    else
                    {
                        HttpContext.Current.Response.Write("1");
                    }
                }
                else
                {
                    if (bll.GetCrmCustomerPublic(new Guid(strJson)))
                    {
                        HttpContext.Current.Response.Write("1");
                    }
                    else
                    {
                        HttpContext.Current.Response.Write("该客户已被处理,不是公海客户,请及时刷新数据!");
                    }
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 订单变更时进行判断操作
        /// </summary>
        /// <param name="strJson"></param>
        private void CheckCrmCustomerOrder(string strJson)
        {
            try
            {
                BTCrmCrustomerOrder bllOrder = new BTCrmCrustomerOrder();
                strJson = this.GetStringFromQueryString("id", ""); //订单ID
                string strType = this.GetStringFromQueryString("type", ""); //0:约场订单 1:销售订单
                if (strType == "0")
                {
                    //类型为约场
                    V_CrmCustomerOrder Orders = bllOrder.GetAllCrmCustomerOrder(new Guid(strJson));
                    if (Orders.TypeID.ToString().ToUpper() == "5E50217A-414E-46D5-89BC-348AD0145FFC")
                    {
                        CrmCustomerOrder(Orders.StateID.ToString().ToUpper());
                    }
                    else
                    {
                        //点击约场订单变更时选中的信息不是约场订单
                        HttpContext.Current.Response.Write("6");
                        return;
                    }
                }
                else
                {
                    //类型为销售
                    V_CrmCustomerInfoOrder Orders = bllOrder.GetAllCrmCustomerInfoOrder(new Guid(strJson));
                    if (Orders.TypeID.ToString().ToUpper() == "5E50217A-414E-46D5-89BC-348AD0145FFC")
                    {
                        //点击销售订单变更时选中的信息不是销售订单
                        HttpContext.Current.Response.Write("7");
                        return;
                    }
                    else
                    {
                        CrmCustomerOrder(Orders.StateID.ToString().ToUpper());
                    }
                }
            }
            catch
            {
                HttpContext.Current.Response.Write("操作异常，如有疑问请联系管理员!");
            }
        }
        /// <summary>
        /// 变更判断
        /// </summary>
        /// <param name="strJson"></param>
        private void CheckCrmCustomerInfoCheckField(string strJson)
        {
            try
            {
                BTCrmCrustomerOrder bllOrder = new BTCrmCrustomerOrder();
                strJson = this.GetStringFromQueryString("id", ""); //客户ID
                string strCode = this.GetStringFromQueryString("code", "");
                IList<V_CrmCustomerInfoDeliver> listOrder = bllOrder.GetAllCrmCustomerInfoOrderByCustomerId(new Guid(strJson), strCode);
                CrmCustomerOrder(listOrder[0].StateID.ToString().ToUpper());
            }
            catch
            {
                HttpContext.Current.Response.Write("操作异常，如有疑问请联系管理员!");
            }
        }
        private void CrmCustomerOrder(string StateId)
        {
            /*if (this.UserName == "admin")
            {
                HttpContext.Current.Response.Write("1"); //新建状态
                return;
            }
            else*/
            {
                if (StateId == "319FDCFA-3948-495B-88B0-1EAB7DC9F138")
                {
                    HttpContext.Current.Response.Write("3");//您当前的订单处于 签核中 状态，不能变更!
                    return;
                }
                else if (StateId == "BDDCAF31-98D4-423A-9275-9288F85E2847")
                {
                    HttpContext.Current.Response.Write("4");//您当前的订单处于 结案 状态，不能变更!
                    return;
                }
                else if (StateId == "C2AF1C1F-6937-40EE-8D40-2E6203E34119")
                {
                    HttpContext.Current.Response.Write("5");//您当前的订单处于 报废 状态，不能变更!
                    return;
                }
                else if (StateId == "C3DACC37-2463-458F-BC45-14AD8722BA45")
                {
                    HttpContext.Current.Response.Write("1"); //新建状态
                    return;
                }
                else
                {
                    HttpContext.Current.Response.Write("2");
                    return;
                }
            }
        }
        /// <summary>
        /// 共享客户时更加部门ID查询出部门所有的人
        /// </summary>
        /// <param name="strJson"></param>
        private void SelectDatEmployeeByDeptId(string strJson)
        {
            try
            {
                string strlistEmployee = "";
                strJson = this.GetStringFromQueryString("id", "");
                IList<V_DatEmployeeForUser> listEmployee = bll.GetDatEmployeeByDeptId(strJson);
                if (listEmployee != null && listEmployee.Count > 0)
                {
                    IList<BaseEntity> _listEmployee = new List<BaseEntity>();
                    foreach (var _e in listEmployee)
                    {
                        _listEmployee.Add(_e);
                    }
                    strlistEmployee = "[" + _listEmployee.ToJSON().Replace("\n", "").Replace("\r", "").Replace("@@", "") + "]";
                    HttpContext.Current.Response.Write(strlistEmployee);
                }
                else
                {
                    HttpContext.Current.Response.Write(strlistEmployee);
                }
            }
            catch
            {
                HttpContext.Current.Response.Write("0");
            }
        }
        /// <summary>
        /// 根据名称查找所有职员信息(分配和共享时查询用)
        /// </summary>
        /// <param name="strJson"></param>
        private void SelectDatEmployeeByName(string strJson)
        {
            try
            {
                string strlistEmployee = "";
                strJson = this.GetStringFromQueryString("id", "");
                IList<V_DatEmployeeForUser> listEmployee = bll.GetDatEmployeeByName(strJson);
                if (listEmployee != null && listEmployee.Count > 0)
                {
                    IList<BaseEntity> _listEmployee = new List<BaseEntity>();
                    foreach (var _e in listEmployee)
                    {
                        _listEmployee.Add(_e);
                    }
                    strlistEmployee = "[" + _listEmployee.ToJSON().Replace("\n", "").Replace("\r", "").Replace("@@", "") + "]";
                    HttpContext.Current.Response.Write(strlistEmployee);
                }
                else
                {
                    HttpContext.Current.Response.Write(strlistEmployee);
                }
            }
            catch
            {
                HttpContext.Current.Response.Write("0");
            }
        }
        /// <summary>
        /// 退回修改客户信息判断
        /// </summary>
        /// <param name="strJson"></param>
        private void CheckCrmCustomerReturn(string strJson)
        {
            BTCrmCustomer bt = new BTCrmCustomer();
            try
            {
                strJson = this.GetStringFromQueryString("id", ""); //客户ID
                int iAllCount = bt.GetPrivateNum("CustomerReturnTime");
                CrmCustomerReturn customerReturn = bt.GetCrmCustomerReturn(new Guid(strJson));
                DateTime dtTime = customerReturn.AddTime.AddDays(iAllCount);
                DateTime dtNow = DateTime.Now;
                if (dtNow > dtTime)
                {
                    //任何人可以修改
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    if (customerReturn.ReciveUser.ToString().Equals(this.UserId.ToString()))
                    {
                        //当前时间内只能接收人自己修改!
                        HttpContext.Current.Response.Write("1");
                    }
                    else
                    {
                        //当前用户不是接收人不能修改该客户信息!
                        HttpContext.Current.Response.Write("2");
                    }
                }
            }
            catch
            {
                HttpContext.Current.Response.Write("0");
            }
        }
        /// <summary>
        /// 消息订单流程同意
        /// </summary>
        /// <param name="strJson"></param>
        private void WorkFlowCrmCustomerOrderAgree(string strJson)
        {
            try
            {
                strJson = this.GetStringFromQueryString("OperatorInstanceId", ""); //流程操作ID
                string strWorkTaskInsId = this.GetStringFromQueryString("WorkTaskInsId", "");

                string msgClaim = workFlowServiceClient.TaskClaim(this.User.LoginName, strJson);
                string msgRun = workFlowServiceClient.Run(this.User.LoginName, strJson, "提交");
                HttpContext.Current.Response.Write("1");
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 价值业绩流程同意 --上级总监
        /// </summary>
        /// <param name="strJson"></param>
        private void WorkFlowCrmValueAgreeS(string strJson)
        {
            try
            {
                string strSql = string.Format("update CrmValue set  DliverState='" + this.GetStringFromQueryString("DliverState", "") + "' where ID='" + this.GetStringFromQueryString("ID", "") + "'");
                int iResult = bll.RunSqlCommand(strSql);

                if (iResult > 0)
                {
                    strJson = this.GetStringFromQueryString("OperatorInstanceId", ""); //流程操作ID
                    string strWorkTaskInsId = this.GetStringFromQueryString("WorkTaskInsId", "");
                    string msgClaim = workFlowServiceClient.TaskClaim(this.User.LoginName, strJson);
                    string msgRun = workFlowServiceClient.Run(this.User.LoginName, strJson, "提交");
                    HttpContext.Current.Response.Write("1");
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 价值业绩流程同意 --田文珊
        /// </summary>
        /// <param name="strJson"></param>
        private void WorkFlowCrmValueAgreeT(string strJson)
        {
            try
            {
                int iResult = 0;
                IDataParameter[] _Parameters = new IDataParameter[] { };
                DbSql db = new DbSql();
                CrmValue instance = (CrmValue)Globals.JSonToObject<CrmValue>(strJson);
                Globals.SetPropertyValue(instance, "AddUser", this.UserId);
                SqlParameter ID = new SqlParameter("@ID", SqlDbType.UniqueIdentifier, 50);
                ID.Direction = ParameterDirection.Input;
                ID.Value = instance.ID;
                SqlParameter CustomerID = new SqlParameter("@CustomerID", SqlDbType.UniqueIdentifier, 50);
                CustomerID.Direction = ParameterDirection.Input;
                CustomerID.Value = instance.CustomerID;
                SqlParameter DliverState = new SqlParameter("@DliverState", SqlDbType.UniqueIdentifier, 50);
                DliverState.Direction = ParameterDirection.Input;
                DliverState.Value = instance.DliverState;
                SqlParameter TaskShare = new SqlParameter("@TaskShare", SqlDbType.NVarChar, 2000);
                TaskShare.Direction = ParameterDirection.Input;
                TaskShare.Value = instance.TaskShare;
                SqlParameter TaskExplain = new SqlParameter("@TaskExplain", SqlDbType.NVarChar, 200);
                TaskExplain.Direction = ParameterDirection.Input;
                TaskExplain.Value = instance.TaskExplain;
                SqlParameter ValueType = new SqlParameter("@ValueType", SqlDbType.Char, 1);
                ValueType.Direction = ParameterDirection.Input;
                ValueType.Value = instance.ValueType;
                SqlParameter IsClassSign = new SqlParameter("@IsClassSign", SqlDbType.Char, 1);
                IsClassSign.Direction = ParameterDirection.Input;
                IsClassSign.Value = instance.IsClassSign;
                SqlParameter DevType = new SqlParameter("@DevType", SqlDbType.Char, 1);
                DevType.Direction = ParameterDirection.Input;
                DevType.Value = instance.DevType;
                SqlParameter IsTrainAgain = new SqlParameter("@IsTrainAgain", SqlDbType.Char, 1);
                IsTrainAgain.Direction = ParameterDirection.Input;
                IsTrainAgain.Value = instance.IsTrainAgain;
                SqlParameter IsPayOrder = new SqlParameter("@IsPayOrder", SqlDbType.Char, 1);
                IsPayOrder.Direction = ParameterDirection.Input;
                IsPayOrder.Value = instance.IsPayOrder;
                SqlParameter IsClassCEO = new SqlParameter("@IsClassCEO", SqlDbType.Char, 1);
                IsClassCEO.Direction = ParameterDirection.Input;
                IsClassCEO.Value = instance.IsClassCEO;
                SqlParameter IsWestPoint = new SqlParameter("@IsWestPoint", SqlDbType.Char, 1);
                IsWestPoint.Direction = ParameterDirection.Input;
                IsWestPoint.Value = instance.IsWestPoint;
                SqlParameter IsSalon = new SqlParameter("@IsSalon", SqlDbType.Char, 1);
                IsSalon.Direction = ParameterDirection.Input;
                IsSalon.Value = instance.IsSalon;
                SqlParameter EPIsClassSign = new SqlParameter("@EPIsClassSign", SqlDbType.Char, 1);
                EPIsClassSign.Direction = ParameterDirection.Input;
                EPIsClassSign.Value = instance.EPIsClassSign;
                SqlParameter EPClassPay = new SqlParameter("@EPClassPay", SqlDbType.Char, 1);
                EPClassPay.Direction = ParameterDirection.Input;
                EPClassPay.Value = instance.EPClassPay;
                SqlParameter EPMoney = new SqlParameter("@EPMoney", SqlDbType.Decimal, 18);
                EPMoney.Direction = ParameterDirection.Input;
                EPMoney.Value = instance.EPMoney;
                SqlParameter DevCustomerType = new SqlParameter("@DevCustomerType", SqlDbType.NVarChar, 100);
                DevCustomerType.Direction = ParameterDirection.Input;
                DevCustomerType.Value = instance.DevCustomerType;
                SqlParameter ProductList = new SqlParameter("@ProductList", SqlDbType.NVarChar, 200);
                ProductList.Direction = ParameterDirection.Input;
                ProductList.Value = instance.ProductList;
                SqlParameter SaleRoad = new SqlParameter("@SaleRoad", SqlDbType.NVarChar, 200);
                SaleRoad.Direction = ParameterDirection.Input;
                SaleRoad.Value = instance.SaleRoad;
                SqlParameter Amount = new SqlParameter("@Amount", SqlDbType.NVarChar, 50);
                Amount.Direction = ParameterDirection.Input;
                Amount.Value = instance.Amount;
                SqlParameter LongDateAddress = new SqlParameter("@LongDateAddress", SqlDbType.NVarChar, 50);
                LongDateAddress.Direction = ParameterDirection.Input;
                LongDateAddress.Value = instance.LongDateAddress;
                SqlParameter PayMoneyTotal = new SqlParameter("@PayMoneyTotal", SqlDbType.Decimal, 18);
                PayMoneyTotal.Direction = ParameterDirection.Input;
                PayMoneyTotal.Value = instance.PayMoneyTotal;
                SqlParameter DevCustomerName = new SqlParameter("@DevCustomerName", SqlDbType.NVarChar, 100);
                DevCustomerName.Direction = ParameterDirection.Input;
                DevCustomerName.Value = instance.DevCustomerName;
                SqlParameter TrainDateAddress = new SqlParameter("@TrainDateAddress", SqlDbType.NVarChar, 100);
                TrainDateAddress.Direction = ParameterDirection.Input;
                TrainDateAddress.Value = instance.TrainDateAddress;
                SqlParameter CEODateAddress = new SqlParameter("@CEODateAddress", SqlDbType.NVarChar, 100);
                CEODateAddress.Direction = ParameterDirection.Input;
                CEODateAddress.Value = instance.CEODateAddress;
                SqlParameter UnSignClassReason = new SqlParameter("@UnSignClassReason", SqlDbType.NVarChar, 200);
                UnSignClassReason.Direction = ParameterDirection.Input;
                UnSignClassReason.Value = instance.UnSignClassReason;
                SqlParameter EPDateAddress = new SqlParameter("@EPDateAddress", SqlDbType.NVarChar, 100);
                EPDateAddress.Direction = ParameterDirection.Input;
                EPDateAddress.Value = instance.EPDateAddress;
                SqlParameter AgainBuyDate = new SqlParameter("@AgainBuyDate", SqlDbType.NVarChar, 50);
                AgainBuyDate.Direction = ParameterDirection.Input;
                AgainBuyDate.Value = instance.AgainBuyDate;
                SqlParameter AgainBuyProduct = new SqlParameter("@AgainBuyProduct", SqlDbType.NVarChar, 200);
                AgainBuyProduct.Direction = ParameterDirection.Input;
                AgainBuyProduct.Value = instance.AgainBuyProduct;
                SqlParameter EXP1 = new SqlParameter("@EXP1", SqlDbType.NVarChar, 100);
                EXP1.Direction = ParameterDirection.Input;
                EXP1.Value = instance.EXP1;
                SqlParameter EXP2 = new SqlParameter("@EXP2", SqlDbType.NVarChar, 100);
                EXP2.Direction = ParameterDirection.Input;
                EXP2.Value = instance.EXP2;
                SqlParameter EXP3 = new SqlParameter("@EXP3", SqlDbType.NVarChar, 100);
                EXP3.Direction = ParameterDirection.Input;
                EXP3.Value = instance.EXP3;
                SqlParameter EXP4 = new SqlParameter("@EXP4", SqlDbType.NVarChar, 100);
                EXP4.Direction = ParameterDirection.Input;
                EXP4.Value = instance.EXP4;
                SqlParameter AddUser = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
                AddUser.Direction = ParameterDirection.Input;
                AddUser.Value = instance.AddUser;
                SqlParameter EPPayDate = new SqlParameter("@EPPayDate", SqlDbType.NVarChar, 50);
                EPPayDate.Direction = ParameterDirection.Input;
                EPPayDate.Value = instance.EPPayDate;
                SqlParameter FirstDate = new SqlParameter("@FirstDate", SqlDbType.NVarChar, 50);
                FirstDate.Direction = ParameterDirection.Input;
                FirstDate.Value = instance.FirstDate;
                SqlParameter FirstNum = new SqlParameter("@FirstNum", SqlDbType.NVarChar, 50);
                FirstNum.Direction = ParameterDirection.Input;
                FirstNum.Value = instance.FirstNum;
                SqlParameter LastCEO = new SqlParameter("@LastCEO", SqlDbType.Char, 1);
                LastCEO.Direction = ParameterDirection.Input;
                LastCEO.Value = instance.LastCEO;
                SqlParameter CEOAddress = new SqlParameter("@CEOAddress", SqlDbType.NVarChar, 50);
                CEOAddress.Direction = ParameterDirection.Input;
                CEOAddress.Value = instance.CEOAddress;
                SqlParameter LastAddress = new SqlParameter("@LastAddress", SqlDbType.NVarChar, 50);
                LastAddress.Direction = ParameterDirection.Input;
                LastAddress.Value = instance.LastAddress;
                SqlParameter FactTempDate = new SqlParameter("@FactTempDate", SqlDbType.NVarChar, 200);
                FactTempDate.Direction = ParameterDirection.Input;
                FactTempDate.Value = instance.FactTempDate;
                SqlParameter OrderMoney = new SqlParameter("@OrderMoney", SqlDbType.NVarChar, 50);
                OrderMoney.Direction = ParameterDirection.Input;
                OrderMoney.Value = instance.OrderMoney;
                SqlParameter APDate = new SqlParameter("@APDate", SqlDbType.DateTime, 50);
                APDate.Direction = ParameterDirection.Input;
                APDate.Value = instance.APDate;
                SqlParameter WorkFlowId = new SqlParameter("@WorkFlowId", SqlDbType.NVarChar, 50);
                WorkFlowId.Direction = ParameterDirection.Input;
                WorkFlowId.Value = instance.WorkFlowId;
                SqlParameter WorkTaskId = new SqlParameter("@WorkTaskId", SqlDbType.NVarChar, 50);
                WorkTaskId.Direction = ParameterDirection.Input;
                WorkTaskId.Value = instance.WorkTaskId;
                SqlParameter WorkFlowInsId = new SqlParameter("@WorkFlowInsId", SqlDbType.NVarChar, 50);
                WorkFlowInsId.Direction = ParameterDirection.Input;
                WorkFlowInsId.Value = instance.WorkFlowInsId;
                SqlParameter WorkTaskInsId = new SqlParameter("@WorkTaskInsId", SqlDbType.NVarChar, 50);
                WorkTaskInsId.Direction = ParameterDirection.Input;
                WorkTaskInsId.Value = instance.WorkTaskInsId;
                SqlParameter OneMoney = new SqlParameter("@OneMoney", SqlDbType.NVarChar, 500);
                OneMoney.Direction = ParameterDirection.Input;
                OneMoney.Value = instance.OneMoney;
                SqlParameter CName = new SqlParameter("@CName", SqlDbType.UniqueIdentifier, 50);
                CName.Direction = ParameterDirection.Input;
                CName.Value = instance.CName;
                SqlParameter CZName = new SqlParameter("@CZName", SqlDbType.UniqueIdentifier, 50);
                CZName.Direction = ParameterDirection.Input;
                CZName.Value = instance.CZName;
                SqlParameter CTel = new SqlParameter("@CTel", SqlDbType.NVarChar, 50);
                CTel.Direction = ParameterDirection.Input;
                CTel.Value = instance.CTel;
                SqlParameter CZTel = new SqlParameter("@CZTel", SqlDbType.NVarChar, 50);
                CZTel.Direction = ParameterDirection.Input;
                CZTel.Value = instance.CZTel;
                SqlParameter payId = new SqlParameter("@payId", SqlDbType.NVarChar, 500);
                payId.Direction = ParameterDirection.Input;
                payId.Value = GetStringFromQueryString("payId", "");
                SqlParameter ProjectMoney = new SqlParameter("@ProjectMoney", SqlDbType.Decimal, 18);
                ProjectMoney.Direction = ParameterDirection.Input;
                ProjectMoney.Value = instance.ProjectMoney;
                SqlParameter ProjectType = new SqlParameter("@ProjectType", SqlDbType.UniqueIdentifier, 50);
                ProjectType.Direction = ParameterDirection.Input;
                ProjectType.Value = instance.ProjectType;
                SqlParameter IsCOProject = new SqlParameter("@IsCOProject", SqlDbType.Char, 1);
                IsCOProject.Direction = ParameterDirection.Input;
                IsCOProject.Value = instance.IsCOProject;
                SqlParameter IsFirstSale = new SqlParameter("@IsFirstSale", SqlDbType.Char, 1);
                IsFirstSale.Direction = ParameterDirection.Input;
                IsFirstSale.Value = instance.IsFirstSale;
                SqlParameter PackName = new SqlParameter("@PackName", SqlDbType.NVarChar, 50);
                PackName.Direction = ParameterDirection.Input;
                PackName.Value = instance.PackName;
                SqlParameter DevYear = new SqlParameter("@DevYear", SqlDbType.NVarChar, 10);
                DevYear.Direction = ParameterDirection.Input;
                DevYear.Value = instance.DevYear;
                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;
                string strSql = "";
                _Parameters = new IDataParameter[] {ID,
								CustomerID,ValueType,
								TaskShare,
								TaskExplain,
								DevType,
								DevCustomerName,
								DevCustomerType,
								IsTrainAgain,
								AddUser,
								APDate,
								TrainDateAddress,
								IsClassSign,
								IsPayOrder,
								IsClassCEO,
								CEODateAddress,
								IsWestPoint,
								IsSalon,
								UnSignClassReason,
								EPIsClassSign,
								EPDateAddress,
								EPClassPay,
								EPPayDate,
								EPMoney, ProductList,SaleRoad,Amount, PayMoneyTotal,LongDateAddress,
                                FirstDate, FirstNum,LastCEO,CEOAddress,LastAddress,FactTempDate,OrderMoney,EXP1,EXP2,EXP3,EXP4, AgainBuyDate,AgainBuyProduct,
								WorkFlowId,
								WorkTaskId,
								WorkFlowInsId,
								WorkTaskInsId,CName,CTel,CZName,CZTel,payId,DliverState,IsFirstSale,OneMoney,IsCOProject,
ProjectType ,
ProjectMoney,PackName,DevYear, ReturnValue};
                strSql = db.RunProcedureReturnString("sp_AddCrmValue", _Parameters, out iResult);
                if (strSql == "1")
                {
                    if (this.GetStringFromQueryString("view", "") == "0")
                    {
                        HttpContext.Current.Response.Write("1");
                    }
                    else
                    {
                        strJson = this.GetStringFromQueryString("OperatorInstanceId", ""); //流程操作ID
                        string strWorkTaskInsId = this.GetStringFromQueryString("WorkTaskInsId", "");

                        string msgClaim = workFlowServiceClient.TaskClaim(this.User.LoginName, strJson);
                        string msgRun = workFlowServiceClient.Run(this.User.LoginName, strJson, "提交");
                        HttpContext.Current.Response.Write("1");
                    }
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 消息订单流程同意(最后一个节点)
        /// </summary>
        /// <param name="strJson"></param>
        private void WorkFlowCrmCustomerOrderAgrees(string strJson)
        {
            try
            {
                string strWorkFlowInsId = this.GetStringFromQueryString("WorkFlowInsId", "");
                /*string strSql = string.Format("update CrmCustomerOrder set StateID='AF73673F-9FEC-4D14-ACFD-B0FCE08D6FFA' " +
                                              " where WorkFlowInsId='{0}'", strWorkFlowInsId);
                int iResult = bll.RunSqlCommand(strSql);*/
                int iRowAffected = 0;
                IDataParameter[] _Parameters = new IDataParameter[] { };
                DbSql db = new DbSql();
                SqlParameter WorkFlowInsId = new SqlParameter("@WorkFlowInsId", SqlDbType.UniqueIdentifier, 50);
                WorkFlowInsId.Direction = ParameterDirection.Input;
                WorkFlowInsId.Value = new Guid(strWorkFlowInsId);
                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;
                _Parameters = new IDataParameter[] { WorkFlowInsId, ReturnValue };
                string iResult = db.RunProcedureReturnString("sp_UpdateCrmCustomerOrderState", _Parameters, out iRowAffected);
                if (iResult == "1")
                {
                    strJson = this.GetStringFromQueryString("OperatorInstanceId", ""); //流程操作ID
                    string strWorkTaskInsId = this.GetStringFromQueryString("WorkTaskInsId", "");

                    string msgClaim = workFlowServiceClient.TaskClaim(this.User.LoginName, strJson);
                    string msgRun = workFlowServiceClient.Run(this.User.LoginName, strJson, "提交");
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("2");//更新订单状态失败
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 消息订单流程不同意(退回)
        /// </summary>
        /// <param name="strJson"></param>
        private void WorkFlowCrmCustomerOrderUnAgree(string strJson)
        {
            try
            {
                strJson = this.GetStringFromQueryString("OperatorInstanceId", ""); //流程操作ID
                string strWorkFlowId = this.GetStringFromQueryString("WorkflowId", ""); //
                string strWorkTaskId = this.GetStringFromQueryString("WorktaskId", "");
                string strWorkFlowInsId = this.GetStringFromQueryString("WorkflowInsId", "");
                string strWorkTaskInsId = this.GetStringFromQueryString("WorktaskInsId", "");
                string strMessage = this.GetStringFromQueryString("msg", "");//退回意见

                string msgClaim = workFlowServiceClient.TaskClaim(this.User.LoginName, strJson);

                ZX.CRM.Web.CrmWorkFlowService.AuditMessage am = new ZX.CRM.Web.CrmWorkFlowService.AuditMessage();
                am.AuditId = Guid.NewGuid().ToString();
                am.WorkflowId = strWorkFlowId;
                am.WorkflowInsId = strWorkFlowInsId;
                am.WorktaskId = strWorkTaskId;
                am.WorktaskInsId = strWorkTaskInsId;
                am.OperatorInsId = strJson;
                am.AuditUserId = this.User.LoginName;
                am.AuditUserName = this.User.UName;
                am.AuditArch = "";
                am.AuditDuty = "";
                am.AuditResult = "拒绝";
                am.Message = strMessage;
                workFlowServiceClient.InsertAuditMessage(am);

                //string msgBack = client.TaskBack(this.User.LoginName, strJson);
                string msgBack = workFlowServiceClient.TaskBackApplicant(this.User.LoginName, strJson);
                HttpContext.Current.Response.Write("1");
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 大课流程退回
        /// </summary>
        /// <param name="strJson"></param>
        private void WorkFlowCrmDeliverMajorUnAgree(string strJson)
        {
            try
            {
                strJson = this.GetStringFromQueryString("OperatorInstanceId", ""); //流程操作ID
                string strWorkFlowId = this.GetStringFromQueryString("WorkflowId", ""); //
                string strWorkTaskId = this.GetStringFromQueryString("WorktaskId", "");
                string strWorkFlowInsId = this.GetStringFromQueryString("WorkflowInsId", "");
                string strWorkTaskInsId = this.GetStringFromQueryString("WorktaskInsId", "");
                string strMessage = this.GetStringFromQueryString("msg", "");//退回意见

                string msgClaim = workFlowServiceClient.TaskClaim(this.User.LoginName, strJson);

                ZX.CRM.Web.CrmWorkFlowService.AuditMessage am = new ZX.CRM.Web.CrmWorkFlowService.AuditMessage();
                am.AuditId = Guid.NewGuid().ToString();
                am.WorkflowId = strWorkFlowId;
                am.WorkflowInsId = strWorkFlowInsId;
                am.WorktaskId = strWorkTaskId;
                am.WorktaskInsId = strWorkTaskInsId;
                am.OperatorInsId = strJson;
                am.AuditUserId = this.User.LoginName;
                am.AuditUserName = this.User.UName;
                am.AuditArch = "";
                am.AuditDuty = "";
                am.AuditResult = "拒绝";
                am.Message = strMessage;
                workFlowServiceClient.InsertAuditMessage(am);

                //string msgBack = client.TaskBack(this.User.LoginName, strJson);
                string msgBack = workFlowServiceClient.TaskBackApplicant(this.User.LoginName, strJson);
                HttpContext.Current.Response.Write("1");
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 内训流程退回
        /// </summary>
        /// <param name="strJson"></param>
        private void WorkFlowCrmDeliverTrainUnAgree(string strJson)
        {
            try
            {
                strJson = this.GetStringFromQueryString("OperatorInstanceId", ""); //流程操作ID
                string strWorkFlowId = this.GetStringFromQueryString("WorkflowId", ""); //
                string strWorkTaskId = this.GetStringFromQueryString("WorktaskId", "");
                string strWorkFlowInsId = this.GetStringFromQueryString("WorkflowInsId", "");
                string strWorkTaskInsId = this.GetStringFromQueryString("WorktaskInsId", "");
                string strMessage = this.GetStringFromQueryString("msg", "");//退回意见

                string msgClaim = workFlowServiceClient.TaskClaim(this.User.LoginName, strJson);

                ZX.CRM.Web.CrmWorkFlowService.AuditMessage am = new ZX.CRM.Web.CrmWorkFlowService.AuditMessage();
                am.AuditId = Guid.NewGuid().ToString();
                am.WorkflowId = strWorkFlowId;
                am.WorkflowInsId = strWorkFlowInsId;
                am.WorktaskId = strWorkTaskId;
                am.WorktaskInsId = strWorkTaskInsId;
                am.OperatorInsId = strJson;
                am.AuditUserId = this.User.LoginName;
                am.AuditUserName = this.User.UName;
                am.AuditArch = "";
                am.AuditDuty = "";
                am.AuditResult = "拒绝";
                am.Message = strMessage;
                workFlowServiceClient.InsertAuditMessage(am);

                string msgBack = workFlowServiceClient.TaskBack(this.User.LoginName, strJson);
                //string msgBack = client.TaskBackApplicant(this.User.LoginName, strJson);
                HttpContext.Current.Response.Write("1");
            }
            catch
            {
                HttpContext.Current.Response.Write("0");
            }
        }
        /// <summary>
        /// 英才学校流程退回
        /// </summary>
        /// <param name="strJson"></param>
        private void WorkFlowCrmDeliverHrUnAgree(string strJson)
        {
            try
            {
                strJson = this.GetStringFromQueryString("OperatorInstanceId", ""); //流程操作ID
                string strWorkFlowId = this.GetStringFromQueryString("WorkflowId", ""); //
                string strWorkTaskId = this.GetStringFromQueryString("WorktaskId", "");
                string strWorkFlowInsId = this.GetStringFromQueryString("WorkflowInsId", "");
                string strWorkTaskInsId = this.GetStringFromQueryString("WorktaskInsId", "");
                string strMessage = this.GetStringFromQueryString("msg", "");//退回意见

                string msgClaim = workFlowServiceClient.TaskClaim(this.User.LoginName, strJson);

                ZX.CRM.Web.CrmWorkFlowService.AuditMessage am = new ZX.CRM.Web.CrmWorkFlowService.AuditMessage();
                am.AuditId = Guid.NewGuid().ToString();
                am.WorkflowId = strWorkFlowId;
                am.WorkflowInsId = strWorkFlowInsId;
                am.WorktaskId = strWorkTaskId;
                am.WorktaskInsId = strWorkTaskInsId;
                am.OperatorInsId = strJson;
                am.AuditUserId = this.User.LoginName;
                am.AuditUserName = this.User.UName;
                am.AuditArch = "";
                am.AuditDuty = "";
                am.AuditResult = "拒绝";
                am.Message = strMessage;
                workFlowServiceClient.InsertAuditMessage(am);

                string msgBack = workFlowServiceClient.TaskBack(this.User.LoginName, strJson);
                //string msgBack = client.TaskBackApplicant(this.User.LoginName, strJson);
                HttpContext.Current.Response.Write("1");
            }
            catch
            {
                HttpContext.Current.Response.Write("0");
            }
        }
        /// <summary>
        /// 项目流程退回
        /// </summary>
        /// <param name="strJson"></param>
        private void WorkFlowCrmDeliverProjectUnAgree(string strJson)
        {
            try
            {
                strJson = this.GetStringFromQueryString("OperatorInstanceId", ""); //流程操作ID
                string strWorkFlowId = this.GetStringFromQueryString("WorkflowId", ""); //
                string strWorkTaskId = this.GetStringFromQueryString("WorktaskId", "");
                string strWorkFlowInsId = this.GetStringFromQueryString("WorkflowInsId", "");
                string strWorkTaskInsId = this.GetStringFromQueryString("WorktaskInsId", "");
                string strMessage = this.GetStringFromQueryString("msg", "");//退回意见

                string msgClaim = workFlowServiceClient.TaskClaim(this.User.LoginName, strJson);

                ZX.CRM.Web.CrmWorkFlowService.AuditMessage am = new ZX.CRM.Web.CrmWorkFlowService.AuditMessage();
                am.AuditId = Guid.NewGuid().ToString();
                am.WorkflowId = strWorkFlowId;
                am.WorkflowInsId = strWorkFlowInsId;
                am.WorktaskId = strWorkTaskId;
                am.WorktaskInsId = strWorkTaskInsId;
                am.OperatorInsId = strJson;
                am.AuditUserId = this.User.LoginName;
                am.AuditUserName = this.User.UName;
                am.AuditArch = "";
                am.AuditDuty = "";
                am.AuditResult = "拒绝";
                am.Message = strMessage;
                workFlowServiceClient.InsertAuditMessage(am);

                string msgBack = workFlowServiceClient.TaskBack(this.User.LoginName, strJson);
                //string msgBack = client.TaskBackApplicant(this.User.LoginName, strJson);
                HttpContext.Current.Response.Write("1");
            }
            catch
            {
                HttpContext.Current.Response.Write("0");
            }
        }
        /// <summary>
        /// 价值业绩流程退回
        /// </summary>
        /// <param name="strJson"></param>
        private void WorkFlowCrmValueUnAgree(string strJson)
        {
            try
            {
                strJson = this.GetStringFromQueryString("OperatorInstanceId", ""); //流程操作ID
                string strWorkFlowId = this.GetStringFromQueryString("WorkflowId", ""); //
                string strWorkTaskId = this.GetStringFromQueryString("WorktaskId", "");
                string strWorkFlowInsId = this.GetStringFromQueryString("WorkflowInsId", "");
                string strWorkTaskInsId = this.GetStringFromQueryString("WorktaskInsId", "");
                string strMessage = this.GetStringFromQueryString("msg", "");//退回意见

                string msgClaim = workFlowServiceClient.TaskClaim(this.User.LoginName, strJson);

                ZX.CRM.Web.CrmWorkFlowService.AuditMessage am = new ZX.CRM.Web.CrmWorkFlowService.AuditMessage();
                am.AuditId = Guid.NewGuid().ToString();
                am.WorkflowId = strWorkFlowId;
                am.WorkflowInsId = strWorkFlowInsId;
                am.WorktaskId = strWorkTaskId;
                am.WorktaskInsId = strWorkTaskInsId;
                am.OperatorInsId = strJson;
                am.AuditUserId = this.User.LoginName;
                am.AuditUserName = this.User.UName;
                am.AuditArch = "";
                am.AuditDuty = "";
                am.AuditResult = "拒绝";
                am.Message = strMessage;
                workFlowServiceClient.InsertAuditMessage(am);

                //string msgBack = client.TaskBack(this.User.LoginName, strJson);
                string msgBack = workFlowServiceClient.TaskBackApplicant(this.User.LoginName, strJson);
                HttpContext.Current.Response.Write("1");
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 根据名称判断用户是否存在  
        /// </summary>
        /// <param name="useName"></param>
        private void CheckDatUserByUName(string useName)
        {
            try
            {
                BUser buser = new BUser();
                DatUser du = buser.GetDatUserByUName(useName);
                if (du != null)
                {
                    HttpContext.Current.Response.Write(du.UserID);
                }
                else
                {
                    HttpContext.Current.Response.Write("1");//系统中不存在改用户
                }
            }
            catch
            {
                HttpContext.Current.Response.Write("0");
            }
        }
        /// <summary>
        /// 检查客户是否已下过约场订单
        /// </summary>
        /// <param name="CustomerId"></param>
        private void CheckCustomerOrder(string CustomerId)
        {
            try
            {
                BTCrmCrustomerOrder bll = new BTCrmCrustomerOrder();
                IList<CrmCustomerOrder> ListCustomerOrder = bll.CheckCustomerOrder(new Guid(CustomerId));
                if (ListCustomerOrder != null && ListCustomerOrder.Count > 0)
                {
                    for (int i = 0; i < ListCustomerOrder.Count; i++)
                    {
                        //订单状态为报废或结案
                        if ((ListCustomerOrder[i].StateID.ToString().ToUpper() != "C2AF1C1F-6937-40EE-8D40-2E6203E34119") &&
                            (ListCustomerOrder[i].StateID.ToString().ToUpper() != "BDDCAF31-98D4-423A-9275-9288F85E2847"))
                        {
                            //已下约场订单,并且当前订单状态不为报废或结案
                            HttpContext.Current.Response.Write("2");
                            return;
                        }
                    }
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("1");
                }
            }
            catch
            {
                HttpContext.Current.Response.Write("0");
            }
        }
        /// <summary>
        /// 知道了
        /// </summary>
        /// <param name="strOperationId"></param>
        private void CheckCrmCustomerOrderOK(string strOperationId)
        {
            try
            {
                string strOperatorInstanceId = this.GetStringFromQueryString("OperatorInstanceId", "");

                string msg1 = workFlowServiceClient.Run(this.User.LoginName, strOperatorInstanceId, "提交");
                HttpContext.Current.Response.Write("1");
            }
            catch
            {
                HttpContext.Current.Response.Write("0");
            }
        }
        /// <summary>
        /// 加载大课已交付数量
        /// </summary>
        /// <param name="OrderProductId"></param>
        private void CheckCrmDeliverMajorPayAccount(string OrderProductId)
        {
            try
            {
                OrderProductId = this.GetStringFromQueryString("id", "");
                BCrmDeliverMajor bll = new BCrmDeliverMajor();
                int iCount = bll.GetDeliverMajorPayAccount(new Guid(OrderProductId));
                HttpContext.Current.Response.Write(iCount);
            }
            catch
            {
                HttpContext.Current.Response.Write("00");
            }
        }
        /// <summary>
        /// 加载英才学校已交付数量
        /// </summary>
        /// <param name="OrderProductId"></param>
        private void CheckCrmDeliverHrPayAccount(string OrderProductId)
        {
            try
            {
                OrderProductId = this.GetStringFromQueryString("id", "");
                DbSql ds = new DbSql();
                int iJfCount = ds.GetRowCount("CrmMajorStudentHr", string.Format(" MajorID in(select ID from CrmDeliverHr where OrderProductID='{0}') and (StudentState=2 or StudentState=1 or StudentState=3 or StudentState=5 )", OrderProductId));
                int iTjCount = ds.GetRowCount("CrmMajorStudentHr", string.Format(" MajorID in(select ID from CrmDeliverHr where OrderProductID='{0}' and StudentState<>4)", OrderProductId));
                HttpContext.Current.Response.Write(iJfCount.ToString() + "," + iTjCount.ToString());
            }
            catch
            {
                HttpContext.Current.Response.Write("00");
            }
        }
        /// <summary>
        /// 查看客户信息是否存在数据
        /// </summary>
        /// <param name="CustomerId"></param>
        private void CheckCrmCustomerInfoID(string CustomerId)
        {
            try
            {
                if (bll.GetCrmPrivateCustomer(new Guid(CustomerId)))
                {
                    IList<CrmCustomerInfo> ListCutomerInfo = bll.GetCrmCustomerInfo(new Guid(CustomerId));
                    if (ListCutomerInfo != null && ListCutomerInfo.Count > 0)
                    {
                        HttpContext.Current.Response.Write("1");
                    }
                    else
                    {
                        HttpContext.Current.Response.Write("0");
                    }
                }
                else
                {
                    HttpContext.Current.Response.Write("0");
                }
            }
            catch
            {
                HttpContext.Current.Response.Write("0");
            }
        }
        /// <summary>
        /// 根据用户ID获取产品期数
        /// </summary>
        /// <returns></returns>
        private void CheckCrmProductLayout()
        {
            try
            {
                string strUserId = this.GetStringFromQueryString("uid", "");
                BCrmProductLayout bll = new BCrmProductLayout();
                IList<V_CrmProductLayout> list = bll.GetProductLayoutByUserId(new Guid(strUserId));
                if (list != null && list.Count > 0)
                {
                    IList<BaseEntity> _listLayout = new List<BaseEntity>();
                    foreach (var _e in list)
                    {
                        _listLayout.Add(_e);
                    }
                    string strLayout = _listLayout.ToJSON().Replace("\n", "").Replace("\r", "").Replace("@@", "");
                    HttpContext.Current.Response.Write(strLayout);
                }
                else
                {
                    HttpContext.Current.Response.Write("0");
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write("0");
            }
        }
        /// <summary>
        /// 获取课程规划期数中的业绩归属
        /// </summary>
        private void CheckMajorStudentDeptName()
        {
            try
            {
                BCrmDeliverMajor bll = new BCrmDeliverMajor();
                string strId = this.GetStringFromQueryString("id", "");
                IList<V_CrmDeliverMajorStudent> listDeptName = bll.GetAllDeptNameByProductLayoutID(new Guid(strId));
                if (listDeptName != null && listDeptName.Count > 0)
                {
                    IList<BaseEntity> _listDeptName = new List<BaseEntity>();
                    foreach (var _e in listDeptName)
                    {
                        _listDeptName.Add(_e);
                    }
                    string strDeptName = "[" + _listDeptName.ToJSON().Replace("\n", "").Replace("\r", "").Replace("@@", "") + "]";
                    HttpContext.Current.Response.Write(strDeptName);
                }
                else
                {
                    HttpContext.Current.Response.Write("0");
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 获取课程规划期数中的客户经理
        /// </summary>
        private void CheckMajorStudentCustomerMgrName()
        {
            try
            {
                BCrmDeliverMajor bll = new BCrmDeliverMajor();
                string strId = this.GetStringFromQueryString("id", "");
                IList<V_CrmDeliverMajorStudent> listCustomerMgrName = bll.GetAllCustomerMgrNameByProductLayoutID(new Guid(strId));
                if (listCustomerMgrName != null && listCustomerMgrName.Count > 0)
                {
                    IList<BaseEntity> _CustomerMgrName = new List<BaseEntity>();
                    foreach (var _e in listCustomerMgrName)
                    {
                        _CustomerMgrName.Add(_e);
                    }
                    string strCustomerMgrName = "[" + _CustomerMgrName.ToJSON().Replace("\n", "").Replace("\r", "").Replace("@@", "") + "]";
                    HttpContext.Current.Response.Write(strCustomerMgrName);
                }
                else
                {
                    HttpContext.Current.Response.Write("0");
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 获取课程规划期数中的团号
        /// </summary>
        private void CheckMajorStudentGroupName()
        {
            try
            {
                BCrmDeliverMajor bll = new BCrmDeliverMajor();
                string strId = this.GetStringFromQueryString("id", "");
                IList<V_CrmDeliverMajorStudent> listGroupName = bll.GetAllGroupNameByProductLayoutID(new Guid(strId));
                if (listGroupName != null && listGroupName.Count > 0)
                {
                    IList<BaseEntity> _listGroupName = new List<BaseEntity>();
                    foreach (var _e in listGroupName)
                    {
                        _listGroupName.Add(_e);
                    }
                    string strGroupName = "[" + _listGroupName.ToJSON().Replace("\n", "").Replace("\r", "").Replace("@@", "") + "]";
                    HttpContext.Current.Response.Write(strGroupName);
                }
                else
                {
                    HttpContext.Current.Response.Write("0");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 签到查询
        /// </summary>
        private void CheckMajorStudentDataList()
        {
            try
            {
                BCrmDeliverMajor bll = new BCrmDeliverMajor();
                string strId = this.GetStringFromQueryString("id", "");
                string strJson = this.GetStringFromQueryString("json", "");
                string[] strList = strJson.Split('$');
                string CustomerName = strList[0];
                string ClassName = strList[1];
                string GroupName = strList[2];
                string DeptName = strList[3];
                string CustomerMgrName = strList[4];
                string IsDecision = strList[5];
                string IsTrain = strList[6];
                string IsSignIn = strList[7];
                IList<V_CrmDeliverMajorStudent> listMajorStudent = bll.CheckMajorStudentDataList(strId, CustomerName, ClassName, GroupName, DeptName, CustomerMgrName, IsDecision, IsTrain, IsSignIn);
                if (listMajorStudent != null && listMajorStudent.Count > 0)
                {
                    IList<BaseEntity> _MajorStudent = new List<BaseEntity>();
                    foreach (var _e in listMajorStudent)
                    {
                        _MajorStudent.Add(_e);
                    }
                    string strMajorStudent = "[" + _MajorStudent.ToJSON().Replace("\n", "").Replace("\r", "").Replace("@@", "") + "]";
                    HttpContext.Current.Response.Write(strMajorStudent);
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        private void CheckMajorStudentSignCount()
        {
            try
            {
                DbSql db = new DbSql();
                string strId = this.GetStringFromQueryString("id", "");
                string strJson = this.GetStringFromQueryString("json", "");
                string[] strList = strJson.Split('$');
                string CustomerName = strList[0];
                string ClassName = strList[1];
                string GroupName = strList[2];
                string DeptName = strList[3];
                string CustomerMgrName = strList[4];
                string IsDecision = strList[5];
                string IsTrain = strList[6];
                string IsSignIn = strList[7];

                string strConditoin = "";
                if (CustomerName != "")
                {
                    strConditoin += " and CustomerName like '%" + CustomerName + "%'";
                }
                if (ClassName != "")
                {
                    strConditoin += " and ClassName like '%" + ClassName + "%'";
                }
                if (GroupName != "")
                {
                    strConditoin += " and GroupName like '%" + GroupName + "%'";
                }
                if (DeptName != "")
                {
                    strConditoin += " and OrderofDeptName like '%" + DeptName + "%'";
                }
                if (CustomerMgrName != "")
                {
                    strConditoin += " and CustomerMgrName like '%" + CustomerMgrName + "%'";
                }
                if (IsDecision != "")
                {
                    strConditoin += " and IsDecision like '%" + IsDecision + "%'";
                }
                if (IsTrain != "")
                {
                    strConditoin += " and IsTrain like '%" + IsTrain + "%'";
                }
                if (IsSignIn != "")
                {
                    strConditoin += " and IsSignIn like '%" + IsSignIn + "%'";
                }

                string strSql = string.Format("select COUNT(*) as TotalCount," +
                                            "SUM(case when t.GroupName<>'0' then 1 else 0 end) as IsGroupCount," +
                                            "SUM(case when t.GroupName='0' then 1 else 0 end) as UnGroupCount," +
                                            "SUM(case when t.IsTrain='1' then 1 else 0 end) as IsTrainCount," +
                                            "SUM(case when t.IsSignIn='1' then 1 else 0 end) as IsSignInCount," +
                                            "SUM(case when t.IsSignIn='0' then 1 else 0 end) as IsUnSignInCount," +
                                            "(select count(distinct CustomerName) from V_CrmDeliverMajorStudent" +
                                            " where Exp5='0' and ProductLayoutID='{0}'" + strConditoin + ") as IsCustomerNameCount" +
                                            " from " +
                                            " (select * from V_CrmDeliverMajorStudent" +
                                            " where Exp5='0' and ProductLayoutID='{0}'" + strConditoin + ") t" +
                                            "", strId);

                DataSet ds = db.Query(strSql);
                DataTable dt = ds.Tables[0];
                HttpContext.Current.Response.Write(dt.Rows[0][0] + "$" + dt.Rows[0][1] + "$" + dt.Rows[0][2] + "$" + dt.Rows[0][3] + "$" + dt.Rows[0][4] + "$" + dt.Rows[0][5] + "$" + dt.Rows[0][6]);
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 选择是否决策人时判断一个客户中只能存在一个决策人
        /// </summary>
        private void CheckCrmDeliverMajorInfoByCustomerId()
        {
            try
            {
                DbSql db = new DbSql();
                string strId = this.GetStringFromQueryString("id", "");
                string strLayoutId = this.GetStringFromQueryString("pid", "");
                string strSql = string.Format("select count(*) from V_CrmDeliverMajorInfo where CustomerId='{0}' " +
                                              "and ProductLayoutID='{1}' and IsDecision=1", strId, strLayoutId);
                int iCount = db.ExecuteScalar(strSql);
                if (iCount > 0)
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write(iCount);
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 保存时客户管理数据时检查是否已存在
        /// </summary>
        private void CheckCustomerOldIsExists()
        {
            try
            {
                int iResult = 0;
                IDataParameter[] _Parameters = new IDataParameter[] { };
                DbSql db = new DbSql();

                int strType = int.Parse(this.GetStringFromQueryString("type", ""));
                int strFlag = int.Parse(this.GetStringFromQueryString("temp", ""));
                string strValue = this.GetStringFromQueryString("value", "");
                string strId = this.GetStringFromQueryString("id", "");

                SqlParameter ID = new SqlParameter("@ID", SqlDbType.UniqueIdentifier, 50);
                ID.Direction = ParameterDirection.Input;
                ID.Value = new Guid(strId);
                SqlParameter CustomerName = new SqlParameter("@CustomerName", SqlDbType.NVarChar, 50);
                CustomerName.Direction = ParameterDirection.Input;
                SqlParameter DecisionTel1 = new SqlParameter("@DecisionTel1", SqlDbType.NVarChar, 20);
                DecisionTel1.Direction = ParameterDirection.Input;
                if (strType == 0)  //验证客户名
                {
                    CustomerName.Value = strValue;
                    DecisionTel1.Value = "";
                }
                else  //验证手机
                {
                    CustomerName.Value = "";
                    DecisionTel1.Value = strValue;
                }
                SqlParameter Flag = new SqlParameter("@Flag", SqlDbType.Int, 1);
                Flag.Direction = ParameterDirection.Input;
                Flag.Value = strFlag;
                SqlParameter Type = new SqlParameter("@Type", SqlDbType.Int, 1);
                Type.Direction = ParameterDirection.Input;
                Type.Value = strType;
                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;

                _Parameters = new IDataParameter[] { ID, CustomerName, DecisionTel1, Flag, Type, ReturnValue };
                string strSql = db.RunProcedureReturnString("sp_CheckCrmCustomerIsExists", _Parameters, out iResult);
                if (strSql == "1")
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write(strSql);
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 获取产品编码
        /// </summary>
        /// <returns></returns>
        private void GetProductCode()
        {
            string strCode = string.Empty;
            strCode = IDMaker.GetSequenceStr("PRO001");
            HttpContext.Current.Response.Write(strCode);
        }
        /// <summary>
        /// 渠道客户退回
        /// </summary>
        private void CheckCrmCustomerChannelUngree()
        {
            try
            {
                string strOperId = this.GetStringFromQueryString("OperatorInstanceId", ""); //流程操作ID
                string strWorkFlowId = this.GetStringFromQueryString("WorkflowId", ""); //
                string strWorkTaskId = this.GetStringFromQueryString("WorktaskId", "");
                string strWorkFlowInsId = this.GetStringFromQueryString("WorkflowInsId", "");
                string strWorkTaskInsId = this.GetStringFromQueryString("WorktaskInsId", "");
                string strMessage = this.GetStringFromQueryString("msg", "");//退回意见

                bool b = bll.UpdateCrmCustomerChannelState(new Guid(strWorkFlowInsId));

                string msgClaim = workFlowServiceClient.TaskClaim(this.User.LoginName, strOperId);

                ZX.CRM.Web.CrmWorkFlowService.AuditMessage am = new ZX.CRM.Web.CrmWorkFlowService.AuditMessage();
                am.AuditId = Guid.NewGuid().ToString();
                am.WorkflowId = strWorkFlowId;
                am.WorkflowInsId = strWorkFlowInsId;
                am.WorktaskId = strWorkTaskId;
                am.WorktaskInsId = strWorkTaskInsId;
                am.OperatorInsId = strOperId;
                am.AuditUserId = this.User.LoginName;
                am.AuditUserName = this.User.UName;
                am.AuditArch = "";
                am.AuditDuty = "";
                am.AuditResult = "拒绝";
                am.Message = strMessage;
                workFlowServiceClient.InsertAuditMessage(am);

                //string msgBack = client.TaskBack(this.User.LoginName, strJson);
                string msgBack = workFlowServiceClient.TaskBackApplicant(this.User.LoginName, strOperId);
                HttpContext.Current.Response.Write("1");
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 获取该客户的工作记录
        /// </summary>
        private void CheckCrmActivityRecord()
        { 
            try
            {
                string strCustomerId = this.GetStringFromQueryString("id", "");
                DbSql db = new DbSql();
                string strSql = string.Format("select dbo.fn_GetCustomerRecordByCustomerId('{0}')", strCustomerId);
                DataTable dt = db.ExecuteQuery(strSql);
                HttpContext.Current.Response.Write(dt.Rows[0][0].ToString());
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        private void CheckCrmCustomerAddTime()
        {
            try
            {
                string strCustomerId = this.GetStringFromQueryString("id", "");
                DbSql db = new DbSql();
                string strSql = string.Format("select AddTime from CrmCustomer where ID='{0}'", strCustomerId);
                DataTable dt = db.ExecuteQuery(strSql);
                if (dt != null && dt.Rows.Count > 0)
                {
                    string tempaddTime = dt.Rows[0][0].ToString();
                    DateTime dtaddTime = DateTime.Parse(tempaddTime);
                    /*string addTime1 = dtaddTime.ToShortDateString();
                    string addTime2 = dtaddTime.ToShortTimeString();
                    string strDate = addTime1 + " " + addTime2;
                    DateTime _dtAddTime = DateTime.Parse(strDate);*/
                    string _tempTime = dtaddTime.ToString("yyyy-MM-dd HH:mm");
                    DateTime _dtaddTime = DateTime.Parse(_tempTime);

                    string tempTime = "2013-05-16";
                    string currentTime = tempTime + " 14:30";
                    DateTime _dtcurrentTime = DateTime.Parse(currentTime);

                    if (_dtaddTime >= _dtcurrentTime)
                    {
                        HttpContext.Current.Response.Write("true");
                    }
                    else
                    {
                        HttpContext.Current.Response.Write("false");
                    }                 
                }
                else
                {
                    HttpContext.Current.Response.Write("false");
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 检查产品是否已有价值业绩
        /// </summary>
        private void CheckCrmValueCount()
        {
            try
            {
                string strOrderProductId = this.GetStringFromQueryString("OrderProductId", "");
                DbSql db = new DbSql();
                string strSql = string.Format("select count(*) from CrmProductPay t1,CrmValue_CrmProductPay t2 " +
                                        "where t1.ID=t2.CrmProductPayID and OrderProductId='{0}'", strOrderProductId);
                int dtCount = db.ExecuteScalar(strSql);
                if (dtCount > 0)
                {
                    HttpContext.Current.Response.Write("0");
                }
                else
                {
                    HttpContext.Current.Response.Write("1");
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }



        /// <summary>
        /// 插入数据
        /// </summary>
        /// <param name="strEntity">实体</param>
        /// <param name="strJson">JSON数据</param>
        private void InsertIntoInfo(string strEntity, string strJson)
        {
            switch (strEntity)
            {
                case "CrmCustomerOrderField":
                case "CrmCustomerOrder":
                    InsertOrder(strEntity, strJson);
                    break;
                case "CrmProductPay":
                case "CrmDeliverMajorP_Order":
                case "CrmValue_CrmProductPay":
                    IsExistPay(strEntity, strJson);
                    break;
                case "CrmPay":
                    InsertPay(strEntity, strJson);
                    break;
                case "CrmLiveOrDerManager":
                    InsertLiveOrder(strEntity, strJson);
                    break;
                case "CrmDeliverMajor":
                    InsertDeliverMajor(strEntity, strJson);
                    break;
                case "CrmDeliverMajorProject":
                    InsertDeliverMajorProject(strEntity, strJson);
                    break;
                case "CrmDeliverTrain":
                    InsertDeliverTrain(strEntity, strJson);
                    break;
                case "CrmValue":
                    InsertCrmValue(strEntity, strJson);
                    break;
                case "CrmDeliverHr":
                    InsertDeliverHr(strEntity, strJson);
                    break;
                case "CrmLinkMan":
                    InsertCrmLinkMan(strEntity, strJson);
                    break;
                case "CrmActivity":
                case "CrmActivityInfo":
                    InsertCrmActivity(strEntity, strJson);
                    break;
                case "CrmCustomerDatLog":
                    InsertCrmCustomerOperator(strEntity, strJson);
                    break;
                case "CrmCustomerRelation":
                    InsertCrmCustomerRelation(strEntity, strJson);
                    break;
                case "CrmOrderModifyOperator":
                    InsertCrmOrderModifyOperator(strEntity, strJson);
                    break;
                case "CustomerHistory":
                    InsertCustomerHistory(strEntity, strJson);
                    break;
                case "CrmProductPack":
                    InsertCrmProductPack(strEntity, strJson);
                    break;
                case "CrmInvoiceCode":
                    InsertCrmInvoiceCode();
                    break;
                case "CrmSubjectManager":
                    InsertCrmSubjectManager(strJson);
                    break;
                case "CrmInvoiceApply":
                    InsertCrmInvoiceApply(strJson);
                    break;
                case "CrmCustomerChannel":
                    InsertCrmCustomerChannel(strJson);
                    break;
                case "CrmLayoutRecord":
                    InsertCrmLayoutRecord(strJson);
                    break;
                default:
                    break;
            }
        }
        /// <summary>
        /// 获取是否存在交付中的缴款单
        /// </summary>
        /// <param name="strEntity">实体</param>
        /// <param name="strJson">JSON数据</param>
        private void IsExistPay(string strEntity, string strJson)
        {
            try
            {
                DataTable dt = null;
                if (strEntity == "CrmValue_CrmProductPay")
                {
                    dt = bll.getIsExistValuePay(GetStringFromQueryString("cid", ""));
                }
                else if (strEntity == "CrmProductPay")
                {
                    dt = bll.getIsExistPay(GetStringFromQueryString("cid", ""));
                }
                else if (strEntity == "CrmDeliverMajorP_Order")
                {
                    dt = bll.getIsExistProject(GetStringFromQueryString("cid", ""));
                }
                if (dt != null && dt.Rows.Count > 0)
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("0");
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 缴款单 
        /// </summary>
        /// <param name="strEntity"></param>
        /// <param name="strJson"></param>
        private void InsertPay(string strEntity, string strJson)
        {
            try
            {
                int iResult = 0;
                IDataParameter[] _Parameters = new IDataParameter[] { };
                DbSql db = new DbSql();
                string strSaveType = this.GetStringFromQueryString("saveType", "");
                CrmPay instance = (CrmPay)Globals.JSonToObject<CrmPay>(strJson);
                Globals.SetPropertyValue(instance, "AddUser", instance.EXP2 == "" ? this.UserId : new Guid(instance.EXP2));
                Globals.SetPropertyValue(instance, "Addtime", System.DateTime.Now);
                BUser bUser = new BUser();
                if (instance.CheckUser == null || instance.CheckUser == "")
                {
                    instance.CheckUser = Guid.Empty.ToString();
                }
                DatUser dus = bUser.GetDatUserByUserId(new Guid(instance.CheckUser));
                SqlParameter Code = new SqlParameter("@Code", SqlDbType.Char, 50);
                Code.Direction = ParameterDirection.Input;
                Code.Value = instance.Code;
                SqlParameter CustomerId = new SqlParameter("@CustomerId", SqlDbType.UniqueIdentifier, 50);
                CustomerId.Direction = ParameterDirection.Input;
                CustomerId.Value = instance.CustomerId;
                SqlParameter DeptId = new SqlParameter("@DeptId", SqlDbType.UniqueIdentifier, 50);
                DeptId.Direction = ParameterDirection.Input;
                DeptId.Value = instance.DeptId;
                SqlParameter Date = new SqlParameter("@Date", SqlDbType.DateTime, 50);
                Date.Direction = ParameterDirection.Input;
                Date.Value = instance.Date;
                //SqlParameter HQ = new SqlParameter("@HQ",SqlDbType.Char,1);
                //HQ.Direction = ParameterDirection.Input;
                //HQ.Value = instance.IsHeadquarter;
                SqlParameter ValutaID = new SqlParameter("@ValutaID", SqlDbType.UniqueIdentifier, 50);
                ValutaID.Direction = ParameterDirection.Input;
                ValutaID.Value = instance.ValutaID;
                SqlParameter PillID = new SqlParameter("@PillID", SqlDbType.UniqueIdentifier, 50);
                PillID.Direction = ParameterDirection.Input;
                PillID.Value = instance.PillID;
                SqlParameter IsFifteenMonth = new SqlParameter("@IsFifteenMonth", SqlDbType.Char, 1);
                IsFifteenMonth.Direction = ParameterDirection.Input;
                IsFifteenMonth.Value = instance.IsFifteenMonth;
                SqlParameter IsProjectOver = new SqlParameter("@IsProjectOver", SqlDbType.Char, 1);
                IsProjectOver.Direction = ParameterDirection.Input;
                IsProjectOver.Value = instance.IsProjectOver;
                SqlParameter IsCEOInnerTrain = new SqlParameter("@IsCEOInnerTrain", SqlDbType.Char, 1);
                IsCEOInnerTrain.Direction = ParameterDirection.Input;
                IsCEOInnerTrain.Value = instance.IsCEOInnerTrain;
                SqlParameter IsInnerTrainSian = new SqlParameter("@IsInnerTrainSian", SqlDbType.Char, 1);
                IsInnerTrainSian.Direction = ParameterDirection.Input;
                IsInnerTrainSian.Value = instance.IsInnerTrainSian;
                SqlParameter IsFisrtSale = new SqlParameter("@IsFisrtSale", SqlDbType.Char, 1);
                IsFisrtSale.Direction = ParameterDirection.Input;
                IsFisrtSale.Value = instance.IsFisrtSale;
                SqlParameter Receipt = new SqlParameter("@Receipt", SqlDbType.NVarChar, 50);
                Receipt.Direction = ParameterDirection.Input;
                Receipt.Value = instance.Receipt;
                SqlParameter InvoiceNum = new SqlParameter("@InvoiceNum", SqlDbType.NVarChar, 50);
                InvoiceNum.Direction = ParameterDirection.Input;
                InvoiceNum.Value = instance.@InvoiceNum;
                SqlParameter Explain = new SqlParameter("@Explain", SqlDbType.NVarChar, 1000);
                Explain.Direction = ParameterDirection.Input;
                Explain.Value = instance.Explain;
                SqlParameter EXP1 = new SqlParameter("@EXP1", SqlDbType.NVarChar, 50);
                EXP1.Direction = ParameterDirection.Input;
                EXP1.Value = instance.EXP1;
                SqlParameter EXP2 = new SqlParameter("@EXP2", SqlDbType.NVarChar, 50);
                EXP2.Direction = ParameterDirection.Input;
                EXP2.Value = instance.EXP2;
                SqlParameter EXP3 = new SqlParameter("@EXP3", SqlDbType.NVarChar, 50);
                EXP3.Direction = ParameterDirection.Input;
                EXP3.Value = instance.EXP3;
                SqlParameter EXP4 = new SqlParameter("@EXP4", SqlDbType.NVarChar, 50);
                EXP4.Direction = ParameterDirection.Input;
                EXP4.Value = instance.EXP4;
                SqlParameter AddUser = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
                AddUser.Direction = ParameterDirection.Input;
                AddUser.Value = instance.AddUser;
                SqlParameter AddTime = new SqlParameter("@AddTime", SqlDbType.DateTime, 50);
                AddTime.Direction = ParameterDirection.Input;
                AddTime.Value = instance.Addtime;
                SqlParameter PayDate = new SqlParameter("@PayDate", SqlDbType.DateTime, 50);
                PayDate.Direction = ParameterDirection.Input;
                //PayDate.Value = (instance.PayDate == null ?DateTime.Parse("1900-01-01") : instance.PayDate);
                PayDate.Value = instance.PayDate;
                SqlParameter FactPayDate = new SqlParameter("@FactPayDate", SqlDbType.DateTime, 50);
                FactPayDate.Direction = ParameterDirection.Input;
                FactPayDate.Value = instance.FactPayDate;
                SqlParameter StateID = new SqlParameter("@State", SqlDbType.UniqueIdentifier, 50);
                StateID.Direction = ParameterDirection.Input;
                StateID.Value = instance.State;
                SqlParameter WorkTaskId = new SqlParameter("@WorkTaskId", SqlDbType.NVarChar, 50);
                WorkTaskId.Direction = ParameterDirection.Input;
                WorkTaskId.Value = instance.WorkTaskId;
                SqlParameter WorkFlowId = new SqlParameter("@WorkFlowId", SqlDbType.NVarChar, 50);
                WorkFlowId.Direction = ParameterDirection.Input;
                WorkFlowId.Value = instance.WorkFlowId;
                SqlParameter WorkFlowInsId = new SqlParameter("@WorkFlowInsId", SqlDbType.NVarChar, 50);
                WorkFlowInsId.Direction = ParameterDirection.Input;
                WorkFlowInsId.Value = instance.WorkFlowInsId;
                SqlParameter WorkTaskInsId = new SqlParameter("@WorkTaskInsId", SqlDbType.NVarChar, 50);
                WorkTaskInsId.Direction = ParameterDirection.Input;
                WorkTaskInsId.Value = instance.WorkTaskInsId;
                SqlParameter CheckUser = new SqlParameter("@CheckUser", SqlDbType.NVarChar, 50);
                CheckUser.Direction = ParameterDirection.Input;
                CheckUser.Value = dus == null ? "" : dus.LoginName;
                SqlParameter ProduectList = new SqlParameter("@ProduectList", SqlDbType.NVarChar, 4000);
                ProduectList.Direction = ParameterDirection.Input;
                ProduectList.Value = instance.ProduectList;
                SqlParameter CZName = new SqlParameter("@CZName", SqlDbType.UniqueIdentifier, 50);
                CZName.Direction = ParameterDirection.Input;
                CZName.Value = instance.CZName;
                SqlParameter FZName = new SqlParameter("@FZName", SqlDbType.UniqueIdentifier, 50);
                FZName.Direction = ParameterDirection.Input;
                FZName.Value = instance.FZName;
                SqlParameter CTeam = new SqlParameter("@CTeam", SqlDbType.UniqueIdentifier, 50);
                CTeam.Direction = ParameterDirection.Input;
                CTeam.Value = instance.CTeam;
                SqlParameter CJName = new SqlParameter("@CJName", SqlDbType.UniqueIdentifier, 50);
                CJName.Direction = ParameterDirection.Input;
                CJName.Value = instance.CJName;
                SqlParameter PayAddress = new SqlParameter("@PayAddress", SqlDbType.NVarChar, 50);
                PayAddress.Direction = ParameterDirection.Input;
                PayAddress.Value = instance.PayAddress;

                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;


                SqlParameter OrderType = new SqlParameter("@OrderType", SqlDbType.Int, 1);
                OrderType.Direction = ParameterDirection.Input;
                OrderType.Value = 0;


                string strSql = "";
                if (strSaveType == "direct")
                {
                    _Parameters = new IDataParameter[] { Code, CustomerId,ValutaID, DeptId,PillID,InvoiceNum,Receipt, StateID,Date,FactPayDate,PayDate,   
                           Explain,EXP1,EXP2,EXP3,EXP4, AddUser, AddTime,  
                        ProduectList, ReturnValue};
                    strSql = db.RunProcedureReturnString("sp_AddCrmDirectPay", _Parameters, out iResult);
                    if (strSql == "1")
                    {
                        HttpContext.Current.Response.Write("1");
                    }
                    else
                    {
                        HttpContext.Current.Response.Write("直接保存数据失败!");
                    }
                }
                else
                {
                    _Parameters = new IDataParameter[] { Code, CustomerId,ValutaID, DeptId,PillID,InvoiceNum, StateID,Date,PayDate,   
                           Explain,EXP1,EXP2,EXP3,EXP4, WorkTaskId,WorkFlowId,WorkFlowInsId,WorkTaskInsId,CheckUser, AddUser, AddTime,  
                        ProduectList,IsFifteenMonth ,
IsProjectOver,
IsCEOInnerTrain,
IsInnerTrainSian,
IsFisrtSale, CZName, FZName, CTeam, CJName,PayAddress, ReturnValue};
                    strSql = db.RunProcedureReturnString("sp_AddCrmPay", _Parameters, out iResult);
                    if (strSql == "1")
                    {
                        string userId = this.User.LoginName;

                        string msg1 = workFlowServiceClient.Start(userId, instance.WorkFlowId, instance.WorkTaskId, instance.WorkFlowInsId, instance.WorkTaskInsId, workFlowServiceClient.GetWorkFlowNO(), "提交", "3", GetStringFromQueryString("cName", "") + "─缴款单", false);
                        //Server.Transfer("../../Crm/BasePages/tooltip.aspx?worktaskInstanceId=" + instance.WorkTaskId);        GetCustomerName(CustomerId.Value.ToString() == "" ? Guid.Empty : new Guid(CustomerId.Value.ToString())) + 
                        HttpContext.Current.Response.Write("1");

                    }
                    else
                    {
                        HttpContext.Current.Response.Write("保存数据失败!");
                    }
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 获取客户名称
        /// </summary>
        /// <param name="cid">客户ID</param>
        /// <returns></returns>
        private string GetCustomerName(Guid cid)
        {
            BTCrmCustomer btcc = new BTCrmCustomer();
            V_CrmCustomerInfo vcci = btcc.GetV_CrmCustomerInfo(cid);
            return vcci == null ? "" : vcci.CustomerName + "的";
        }
        /// <summary>
        /// 获取客户名称
        /// </summary>
        /// <param name="cid">客户ID</param>
        /// <param name="type">类型</param>
        /// <returns></returns>
        private string GetCustomerName(Guid cid,int type)
        {
            BTCrmCustomer btcc = new BTCrmCustomer();
            V_CrmCustomerInfo vcci = btcc.GetV_CrmCustomerInfo(cid);
            return vcci == null ? "" : vcci.CustomerName;
        }
        private void InsertOrder(string strEntity, string strJson)
        {
            int iResult = 0;
            IDataParameter[] _Parameters = new IDataParameter[] { };
            DbSql db = new DbSql();
            try
            {
                CrmCustomerOrder instance = (CrmCustomerOrder)Globals.JSonToObject<CrmCustomerOrder>(strJson);
                Globals.SetPropertyValue(instance, "AddUser", this.UserId);
                Globals.SetPropertyValue(instance, "AddTime", System.DateTime.Now);

                SqlParameter ID = new SqlParameter("@ID", SqlDbType.UniqueIdentifier, 50);
                ID.Direction = ParameterDirection.Input;
                ID.Value = instance.ID;
                SqlParameter Code = new SqlParameter("@Code", SqlDbType.Char, 50);
                Code.Direction = ParameterDirection.Input;
                Code.Value = instance.Code;
                SqlParameter CustomerId = new SqlParameter("@CustomerId", SqlDbType.UniqueIdentifier, 50);
                CustomerId.Direction = ParameterDirection.Input;
                CustomerId.Value = instance.CustomerId;
                SqlParameter DeptId = new SqlParameter("@DeptId", SqlDbType.UniqueIdentifier, 50);
                DeptId.Direction = ParameterDirection.Input;
                DeptId.Value = instance.DeptId;
                SqlParameter Date = new SqlParameter("@Date", SqlDbType.DateTime, 50);
                Date.Direction = ParameterDirection.Input;
                Date.Value = instance.Date;
                SqlParameter TypeID = new SqlParameter("@TypeID", SqlDbType.UniqueIdentifier, 50);
                TypeID.Direction = ParameterDirection.Input;
                TypeID.Value = instance.TypeID;
                SqlParameter ValutaID = new SqlParameter("@ValutaID", SqlDbType.UniqueIdentifier, 50);
                ValutaID.Direction = ParameterDirection.Input;
                ValutaID.Value = instance.ValutaID;
                SqlParameter PillID = new SqlParameter("@PillID", SqlDbType.UniqueIdentifier, 50);
                PillID.Direction = ParameterDirection.Input;
                PillID.Value = instance.PillID;
                SqlParameter CourseLoyoutID = new SqlParameter("@CourseLoyoutID", SqlDbType.UniqueIdentifier, 50);
                CourseLoyoutID.Direction = ParameterDirection.Input;
                CourseLoyoutID.Value = instance.CourseLoyoutID;
                SqlParameter PaymentId = new SqlParameter("@PaymentId", SqlDbType.UniqueIdentifier, 50);
                PaymentId.Direction = ParameterDirection.Input;
                PaymentId.Value = instance.PaymentId;
                SqlParameter Explain = new SqlParameter("@Explain", SqlDbType.NVarChar, 1000);
                Explain.Direction = ParameterDirection.Input;
                Explain.Value = instance.Explain;
                SqlParameter AddUser = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
                AddUser.Direction = ParameterDirection.Input;
                AddUser.Value = instance.AddUser;
                SqlParameter AddTime = new SqlParameter("@AddTime", SqlDbType.DateTime, 50);
                AddTime.Direction = ParameterDirection.Input;
                AddTime.Value = instance.AddTime;
                SqlParameter TotalMoney = new SqlParameter("@TotalMoney", SqlDbType.Decimal, 20);
                TotalMoney.Direction = ParameterDirection.Input;
                TotalMoney.Value = instance.TotalMoney;
                SqlParameter StateID = new SqlParameter("@StateID", SqlDbType.UniqueIdentifier, 50);
                StateID.Direction = ParameterDirection.Input;
                StateID.Value = instance.StateID;

                SqlParameter ProductPackID = new SqlParameter("@ProductPackID", SqlDbType.UniqueIdentifier, 50);
                ProductPackID.Direction = ParameterDirection.Input;
                ProductPackID.Value = instance.ProductPackID;
                SqlParameter IsPerformance = new SqlParameter("@IsPerformance", SqlDbType.Char, 1);
                IsPerformance.Direction = ParameterDirection.Input;
                IsPerformance.Value = instance.IsPerformance;

                SqlParameter ProduectList = new SqlParameter("@ProduectList", SqlDbType.NVarChar, 4000);
                ProduectList.Direction = ParameterDirection.Input;
                ProduectList.Value = instance.ProduectList;
                SqlParameter CustomerZjList = new SqlParameter("@CustomerZjList", SqlDbType.NVarChar, 4000);
                CustomerZjList.Direction = ParameterDirection.Input;
                CustomerZjList.Value = instance.CustomerZjList;
                SqlParameter CustomerServerList = new SqlParameter("@CustomerServerList", SqlDbType.NVarChar, 10000);
                CustomerServerList.Direction = ParameterDirection.Input;
                CustomerServerList.Value = instance.CustomerServerList;

                SqlParameter TeacherId = new SqlParameter("@TeacherId", SqlDbType.UniqueIdentifier, 50);
                TeacherId.Direction = ParameterDirection.Input;
                TeacherId.Value = instance.TeacherId;
                SqlParameter TeacherTime = new SqlParameter("@TeacherTime", SqlDbType.DateTime, 50);
                TeacherTime.Direction = ParameterDirection.Input;
                TeacherTime.Value = instance.TeacherTime;
                SqlParameter TeacherAddress = new SqlParameter("@TeacherAddress", SqlDbType.NVarChar, 50);
                TeacherAddress.Direction = ParameterDirection.Input;
                TeacherAddress.Value = instance.TeacherAddress;
                SqlParameter TeacherType = new SqlParameter("@TeacherType", SqlDbType.NVarChar, 50);
                TeacherType.Direction = ParameterDirection.Input;
                TeacherType.Value = instance.TeacherType;

                SqlParameter LinkManId = new SqlParameter("@LinkManId", SqlDbType.UniqueIdentifier, 50);
                LinkManId.Direction = ParameterDirection.Input;
                LinkManId.Value = instance.LinkManId;
                SqlParameter LinkManCode = new SqlParameter("@LinkManCode", SqlDbType.NVarChar, 15);
                LinkManCode.Direction = ParameterDirection.Input;
                LinkManCode.Value = ZX.BLL.IDMaker.GetSequenceStr("CUS002");
                SqlParameter LinkManName = new SqlParameter("@LinkManName", SqlDbType.NVarChar, 30);
                LinkManName.Direction = ParameterDirection.Input;
                LinkManName.Value = instance.LinkManName;
                SqlParameter LinkManSex = new SqlParameter("@LinkManSex", SqlDbType.NVarChar, 1);
                LinkManSex.Direction = ParameterDirection.Input;
                LinkManSex.Value = instance.LinkManSex;
                SqlParameter LinkManPosition = new SqlParameter("@LinkManPosition", SqlDbType.NVarChar, 20);
                LinkManPosition.Direction = ParameterDirection.Input;
                LinkManPosition.Value = instance.LinkManPosition;
                SqlParameter LinkManTel = new SqlParameter("@LinkManTel", SqlDbType.NVarChar, 20);
                LinkManTel.Direction = ParameterDirection.Input;
                LinkManTel.Value = instance.LinkManTel;

                SqlParameter ZhuYueRenID = new SqlParameter("@ZhuYueRenID", SqlDbType.UniqueIdentifier, 50);
                ZhuYueRenID.Direction = ParameterDirection.Input;
                ZhuYueRenID.Value = instance.ZhuYueRenID;

                SqlParameter WorkFlowId = new SqlParameter("@WorkFlowId", SqlDbType.NVarChar, 50);
                WorkFlowId.Direction = ParameterDirection.Input;
                WorkFlowId.Value = instance.WorkFlowId;
                SqlParameter WorkTaskId = new SqlParameter("@WorkTaskId", SqlDbType.NVarChar, 50);
                WorkTaskId.Direction = ParameterDirection.Input;
                WorkTaskId.Value = instance.WorkTaskId;
                SqlParameter WorkFlowInsId = new SqlParameter("@WorkFlowInsId", SqlDbType.NVarChar, 50);
                WorkFlowInsId.Direction = ParameterDirection.Input;
                WorkFlowInsId.Value = instance.WorkFlowInsId;
                SqlParameter WorkTaskInsId = new SqlParameter("@WorkTaskInsId", SqlDbType.NVarChar, 50);
                WorkTaskInsId.Direction = ParameterDirection.Input;
                WorkTaskInsId.Value = instance.WorkTaskInsId;

                string strOrderType = this.GetStringFromQueryString("orderType", "");
                SqlParameter CheckUser = new SqlParameter("@CheckUser", SqlDbType.NVarChar, 50);
                CheckUser.Direction = ParameterDirection.Input;
                if (strOrderType == "1")
                {
                    string strFz = this.GetStringFromQueryString("fz", "");
                    CheckUser.Value = strFz;
                }
                else
                {
                    CheckUser.Value = instance.CheckUser;
                }
                SqlParameter EXP1 = new SqlParameter("@EXP1", SqlDbType.NVarChar, 40);
                EXP1.Direction = ParameterDirection.Input;
                EXP1.Value = instance.EXP1;

                SqlParameter PresentationType = new SqlParameter("@PresentationType", SqlDbType.UniqueIdentifier, 50);
                PresentationType.Direction = ParameterDirection.Input;
                PresentationType.Value = instance.PresentationType;
                SqlParameter PresentationOrderId = new SqlParameter("@PresentationOrderId", SqlDbType.UniqueIdentifier, 50);
                PresentationOrderId.Direction = ParameterDirection.Input;
                PresentationOrderId.Value = instance.PresentationOrderId;
                SqlParameter PresentationReason = new SqlParameter("@PresentationReason", SqlDbType.NVarChar, 1000);
                PresentationReason.Direction = ParameterDirection.Input;
                PresentationReason.Value = instance.PresentationReason;

                SqlParameter IsHistory = new SqlParameter("@IsHistory", SqlDbType.Char, 1);
                IsHistory.Direction = ParameterDirection.Input;
                IsHistory.Value = instance.IsHistory;

                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;

                SqlParameter OrderType = new SqlParameter();
                if (strEntity == "CrmCustomerOrderField")  //约场订单
                {
                    OrderType = new SqlParameter("@OrderType", SqlDbType.Int, 1);
                    OrderType.Direction = ParameterDirection.Input;
                    OrderType.Value = 0;
                }
                else if (strEntity == "CrmCustomerOrder")  //销售订单
                {
                    OrderType = new SqlParameter("@OrderType", SqlDbType.Int, 1);
                    OrderType.Direction = ParameterDirection.Input;
                    OrderType.Value = 1;
                }
                _Parameters = new IDataParameter[] { ID,Code, CustomerId, DeptId, Date, TypeID, ValutaID, 
                        PillID, CourseLoyoutID, PaymentId, Explain, AddUser, AddTime, TotalMoney, StateID, OrderType,
                        EXP1, ProduectList,CustomerZjList,CustomerServerList,TeacherId,TeacherTime,TeacherAddress,
                        TeacherType,LinkManId,LinkManCode,LinkManName,LinkManSex,LinkManPosition,LinkManTel,ZhuYueRenID,
                        ProductPackID, IsPerformance,WorkFlowId,WorkTaskId,WorkFlowInsId,WorkTaskInsId,
                        CheckUser,PresentationType,PresentationOrderId,PresentationReason,IsHistory,ReturnValue};
                string strSql = db.RunProcedureReturnString("sp_AddCrmCustomerOrder", _Parameters, out iResult);
                if (strSql == "1")
                {
                    if (TypeID.Value.ToString().ToUpper() == "5E50217A-414E-46D5-89BC-348AD0145FFC" ||
                        TypeID.Value.ToString().ToUpper() == "53C8DAE4-F3C9-4995-BB6A-560123574B81") //类型为一推|约场
                    {
                        HttpContext.Current.Response.Write("1");
                    }
                    else
                    {
                        string strFlowCaption = GetStringFromQueryString("cName", "") + "─销售订单";
                        if (strOrderType == "1")  //赠送订单
                        {
                            strFlowCaption = GetStringFromQueryString("cName", "") + "─赠送订单";
                        }
                        else if (strOrderType == "0") //销售订单
                        {
                            strFlowCaption = GetStringFromQueryString("cName", "") + "─销售订单";
                        }
                        string userId = this.User.LoginName;
                        string msg1 = workFlowServiceClient.Start(userId, WorkFlowId.Value.ToString(), WorkTaskId.Value.ToString(),
                             WorkFlowInsId.Value.ToString(), WorkTaskInsId.Value.ToString(), workFlowServiceClient.GetWorkFlowNO(), "提交", "3", strFlowCaption, false);
                        HttpContext.Current.Response.Write("3");
                        return;
                    }
                }
                else if (strSql == "2")
                {
                    //约场订单中该讲师在当前时间段已安排讲场!
                    HttpContext.Current.Response.Write("2");
                }
                else
                {
                    HttpContext.Current.Response.Write(strSql);
                }
            }
            catch(Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 现场销售
        /// </summary>
        /// <param name="strEntity"></param>
        /// <param name="strJson"></param>
        private void InsertLiveOrder(string strEntity, string strJson)
        {
            int iResult = 0;
            IDataParameter[] _Parameters = new IDataParameter[] { };
            DbSql db = new DbSql();
            try
            {
                CrmLiveOrDerManager instance = (CrmLiveOrDerManager)Globals.JSonToObject<CrmLiveOrDerManager>(strJson);
                Globals.SetPropertyValue(instance, "AddUser", this.UserId);
                Globals.SetPropertyValue(instance, "AddTime", System.DateTime.Now);

                SqlParameter ID = new SqlParameter("@ID", SqlDbType.UniqueIdentifier, 50);
                ID.Direction = ParameterDirection.Input;
                ID.Value = instance.ID;

                SqlParameter CustomerId = new SqlParameter("@CustomerId", SqlDbType.UniqueIdentifier, 50);
                CustomerId.Direction = ParameterDirection.Input;
                CustomerId.Value = instance.CustomerID;


                SqlParameter TypeID = new SqlParameter("@PayType", SqlDbType.UniqueIdentifier, 50);
                TypeID.Direction = ParameterDirection.Input;
                TypeID.Value = instance.PayType;

                SqlParameter CourseLoyoutID = new SqlParameter("@CourseLayoutID", SqlDbType.UniqueIdentifier, 50);
                CourseLoyoutID.Direction = ParameterDirection.Input;
                CourseLoyoutID.Value = instance.CourseLayoutID;
                SqlParameter Explain = new SqlParameter("@Explain", SqlDbType.NVarChar, 500);
                Explain.Direction = ParameterDirection.Input;
                Explain.Value = instance.Explain;

                SqlParameter AddUser = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
                AddUser.Direction = ParameterDirection.Input;
                AddUser.Value = instance.AddUser;
                SqlParameter AddTime = new SqlParameter("@AddTime", SqlDbType.DateTime, 50);
                AddTime.Direction = ParameterDirection.Input;
                AddTime.Value = instance.AddTime;
                SqlParameter TotalMoney = new SqlParameter("@TotalMoney", SqlDbType.Decimal, 18);
                TotalMoney.Direction = ParameterDirection.Input;
                TotalMoney.Value = instance.TotalMoney;
                SqlParameter ResignMoney = new SqlParameter("@ResignMoney", SqlDbType.Decimal, 18);
                ResignMoney.Direction = ParameterDirection.Input;
                ResignMoney.Value = instance.ResignMoney;
                SqlParameter POSNum = new SqlParameter("@POSNum", SqlDbType.NVarChar, 30);
                POSNum.Direction = ParameterDirection.Input;
                POSNum.Value = instance.POSNum;
                SqlParameter InvoiceNum = new SqlParameter("@InvoiceNum", SqlDbType.NVarChar, 30);
                InvoiceNum.Direction = ParameterDirection.Input;
                InvoiceNum.Value = instance.InvoiceNum;
                SqlParameter PactNum = new SqlParameter("@PactNum", SqlDbType.NVarChar, 30);
                PactNum.Direction = ParameterDirection.Input;
                PactNum.Value = instance.PactNum;
                SqlParameter ReceiptNum = new SqlParameter("@ReceiptNum", SqlDbType.NVarChar, 30);
                ReceiptNum.Direction = ParameterDirection.Input;
                ReceiptNum.Value = instance.ReceiptNum;
                SqlParameter SignName = new SqlParameter("@SignName", SqlDbType.NVarChar, 1000);
                SignName.Direction = ParameterDirection.Input;
                SignName.Value = instance.NegotiateTeachID;
                SqlParameter ProductPackID = new SqlParameter("@ProductPack", SqlDbType.UniqueIdentifier, 50);
                ProductPackID.Direction = ParameterDirection.Input;
                ProductPackID.Value = instance.ProductPack;
                SqlParameter IsInvoice = new SqlParameter("@IsInvoice", SqlDbType.Char, 1);
                IsInvoice.Direction = ParameterDirection.Input;
                IsInvoice.Value = instance.IsInvoice;
                SqlParameter ProduectList = new SqlParameter("@ProduectList", SqlDbType.NVarChar, 4000);
                ProduectList.Direction = ParameterDirection.Input;
                ProduectList.Value = instance.ProduectList;

                SqlParameter CrmDeliverMajorID = new SqlParameter("@CrmDeliverMajorID", SqlDbType.UniqueIdentifier, 50);
                CrmDeliverMajorID.Direction = ParameterDirection.Input;
                CrmDeliverMajorID.Value = instance.CrmDeliverMajorID;


                SqlParameter TotalRebate = new SqlParameter("@TotalRebate", SqlDbType.NVarChar, 40);
                TotalRebate.Direction = ParameterDirection.Input;
                TotalRebate.Value = instance.TotalRebate.ToString();


                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;


                _Parameters = new IDataParameter[] { ID, CustomerId,
                         CourseLoyoutID, TypeID,POSNum,InvoiceNum,IsInvoice,PactNum,ReceiptNum,  SignName, Explain, AddUser, AddTime, TotalMoney, ResignMoney,
                        TotalRebate, ProduectList,
                        ProductPackID,CrmDeliverMajorID,ReturnValue};
                string strSql = db.RunProcedureReturnString("sp_AddCrmLiveCustomerOrder", _Parameters, out iResult);
                if (strSql == "1")
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("保存数据失败!");
                }
            }
            catch (Exception e)
            {
                HttpContext.Current.Response.Write(e);
            }
        }
        private void InsertDeliverMajor(string strEntity, string strJson)
        {
            int iResult = 0;
            IDataParameter[] _Parameters = new IDataParameter[] { };
            DbSql db = new DbSql();
            try
            {
                CrmDeliverMajor instance = (CrmDeliverMajor)Globals.JSonToObject<CrmDeliverMajor>(strJson);
                Globals.SetPropertyValue(instance, "AddUser", this.UserId);
                Globals.SetPropertyValue(instance, "AddTime", System.DateTime.Now);

                SqlParameter ID = new SqlParameter("@ID", SqlDbType.UniqueIdentifier, 50);
                ID.Direction = ParameterDirection.Input;
                ID.Value = instance.ID;
                SqlParameter Code = new SqlParameter("@Code", SqlDbType.Char, 15);
                Code.Direction = ParameterDirection.Input;
                Code.Value = instance.Code;
                SqlParameter OrderProductID = new SqlParameter("@OrderProductID", SqlDbType.UniqueIdentifier, 50);
                OrderProductID.Direction = ParameterDirection.Input;
                OrderProductID.Value = instance.OrderProductID;
                SqlParameter ProductLayoutID = new SqlParameter("@ProductLayoutID", SqlDbType.UniqueIdentifier, 50);
                ProductLayoutID.Direction = ParameterDirection.Input;
                ProductLayoutID.Value = instance.ProductLayoutID;
                SqlParameter NegotiateTeach = new SqlParameter("@NegotiateTeach", SqlDbType.UniqueIdentifier, 50);
                NegotiateTeach.Direction = ParameterDirection.Input;
                NegotiateTeach.Value = instance.NegotiateTeach;
                SqlParameter ClassServer = new SqlParameter("@ClassServer", SqlDbType.UniqueIdentifier, 50);
                ClassServer.Direction = ParameterDirection.Input;
                ClassServer.Value = instance.ClassServer;
                SqlParameter ClassFrontServer = new SqlParameter("@ClassFrontServer", SqlDbType.UniqueIdentifier, 50);
                ClassFrontServer.Direction = ParameterDirection.Input;
                ClassFrontServer.Value = instance.ClassFrontServer;
                SqlParameter DliverState = new SqlParameter("@DliverState", SqlDbType.UniqueIdentifier, 50);
                DliverState.Direction = ParameterDirection.Input;
                DliverState.Value = instance.DliverState;
                SqlParameter AddUser = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
                AddUser.Direction = ParameterDirection.Input;
                AddUser.Value = instance.AddUser;
                SqlParameter AddTime = new SqlParameter("@AddTime", SqlDbType.DateTime, 50);
                AddTime.Direction = ParameterDirection.Input;
                AddTime.Value = instance.AddTime;
                SqlParameter StudentList = new SqlParameter("@StudentList", SqlDbType.NVarChar, 8000);
                StudentList.Direction = ParameterDirection.Input;
                StudentList.Value = instance.StudentList;

                SqlParameter GradeDeptId = new SqlParameter("@GradeDeptId", SqlDbType.UniqueIdentifier, 50);
                GradeDeptId.Direction = ParameterDirection.Input;
                GradeDeptId.Value = instance.GradeDeptId;
                SqlParameter ConstDeptId = new SqlParameter("@ConstDeptId", SqlDbType.UniqueIdentifier, 50);
                ConstDeptId.Direction = ParameterDirection.Input;
                ConstDeptId.Value = instance.ConstDeptId;
                SqlParameter exp3 = new SqlParameter("@exp3", SqlDbType.NVarChar, 50);
                exp3.Direction = ParameterDirection.Input;
                exp3.Value = instance.exp3;

                SqlParameter WorkFlowId = new SqlParameter("@WorkFlowId", SqlDbType.NVarChar, 50);
                WorkFlowId.Direction = ParameterDirection.Input;
                WorkFlowId.Value = instance.WorkFlowId;
                SqlParameter WorkTaskId = new SqlParameter("@WorkTaskId", SqlDbType.NVarChar, 50);
                WorkTaskId.Direction = ParameterDirection.Input;
                WorkTaskId.Value = instance.WorkTaskId;
                SqlParameter WorkFlowInsId = new SqlParameter("@WorkFlowInsId", SqlDbType.NVarChar, 50);
                WorkFlowInsId.Direction = ParameterDirection.Input;
                WorkFlowInsId.Value = instance.WorkFlowInsId;
                SqlParameter WorkTaskInsId = new SqlParameter("@WorkTaskInsId", SqlDbType.NVarChar, 50);
                WorkTaskInsId.Direction = ParameterDirection.Input;
                WorkTaskInsId.Value = instance.WorkTaskInsId;

                SqlParameter CustomerMgr = new SqlParameter("@CustomerMgr", SqlDbType.UniqueIdentifier, 50);
                CustomerMgr.Direction = ParameterDirection.Input;
                CustomerMgr.Value = instance.CustomerMgr;
                SqlParameter CustomerDirector = new SqlParameter("@CustomerDirector", SqlDbType.UniqueIdentifier, 50);
                CustomerDirector.Direction = ParameterDirection.Input;
                CustomerDirector.Value = instance.CustomerDirector;
                SqlParameter CustomerManager = new SqlParameter("@CustomerManager", SqlDbType.UniqueIdentifier, 50);
                CustomerManager.Direction = ParameterDirection.Input;
                CustomerManager.Value = instance.CustomerManager;

                string strType = this.GetStringFromQueryString("type", "");
                SqlParameter AddType = new SqlParameter("@AddType", SqlDbType.Char, 1);
                AddType.Direction = ParameterDirection.Input;
                AddType.Value = strType;


                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;

                _Parameters = new IDataParameter[] { ID,Code,OrderProductID,ProductLayoutID,NegotiateTeach,
					                        ClassServer,ClassFrontServer,DliverState,GradeDeptId,ConstDeptId,
                                            exp3,AddUser,AddTime,StudentList,WorkFlowId,WorkTaskId,WorkFlowInsId,
                                            WorkTaskInsId,CustomerMgr,CustomerDirector,CustomerManager,
                                            AddType,ReturnValue};
                string strSql = db.RunProcedureReturnString("sp_AddCrmDeliverMajor", _Parameters, out iResult);

                if (strSql == "1")
                {
                    if (instance.WorkTaskId != "")
                    {
                        string userId = this.User.LoginName;

                        string msgClaim = workFlowServiceClient.TaskClaim(this.User.LoginName, strJson);
                        string msgRun = workFlowServiceClient.Start(userId, WorkFlowId.Value.ToString(), WorkTaskId.Value.ToString(),
                             WorkFlowInsId.Value.ToString(), WorkTaskInsId.Value.ToString(), workFlowServiceClient.GetWorkFlowNO(), "提交", "3", GetStringFromQueryString("cName", "") + "─公开课交付申请单", false);
                        HttpContext.Current.Response.Write("1");
                    }
                    else
                    {
                        HttpContext.Current.Response.Write("2");
                    }
                }
                else
                {
                    HttpContext.Current.Response.Write(strSql);
                }
                /*if (strSql == "1")
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("保存数据失败!");
                }*/
            }
            catch
            {
                HttpContext.Current.Response.Write("数据异常!保存失败!");
            }
        }
        /// <summary>
        /// 交付申请单--项目
        /// </summary>
        /// <param name="strEntity"></param>
        /// <param name="strJson"></param>
        private void InsertDeliverMajorProject(string strEntity, string strJson)
        {
            int iResult = 0;
            IDataParameter[] _Parameters = new IDataParameter[] { };
            DbSql db = new DbSql();
            try
            {
                CrmDeliverMajorProject instance = (CrmDeliverMajorProject)Globals.JSonToObject<CrmDeliverMajorProject>(strJson);
                Globals.SetPropertyValue(instance, "AddUser", this.UserId);
                Globals.SetPropertyValue(instance, "AddTime", System.DateTime.Now);

                SqlParameter Code = new SqlParameter("@Code", SqlDbType.Char, 15);
                Code.Direction = ParameterDirection.Input;
                Code.Value = instance.Code;
                SqlParameter ClassFrontServer = new SqlParameter("@ClassFrontServer", SqlDbType.UniqueIdentifier, 50);
                ClassFrontServer.Direction = ParameterDirection.Input;
                ClassFrontServer.Value = instance.ClassFrontServer;
                SqlParameter DliverState = new SqlParameter("@DliverState", SqlDbType.UniqueIdentifier, 50);
                DliverState.Direction = ParameterDirection.Input;
                DliverState.Value = instance.DliverState;
                SqlParameter AddUser = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
                AddUser.Direction = ParameterDirection.Input;
                AddUser.Value = instance.AddUser;
                SqlParameter AddTime = new SqlParameter("@AddTime", SqlDbType.DateTime, 50);
                AddTime.Direction = ParameterDirection.Input;
                AddTime.Value = instance.AddTime.ToString() == "0001-01-01 " ? DateTime.Now : instance.AddTime;
                SqlParameter WorkFlowId = new SqlParameter("@WorkFlowId", SqlDbType.NVarChar, 50);
                WorkFlowId.Direction = ParameterDirection.Input;
                WorkFlowId.Value = instance.WorkFlowId == "" ? Guid.Empty.ToString() : instance.WorkFlowId;
                SqlParameter WorkTaskId = new SqlParameter("@WorkTaskId", SqlDbType.NVarChar, 50);
                WorkTaskId.Direction = ParameterDirection.Input;
                WorkTaskId.Value = instance.WorkTaskId == "" ? Guid.Empty.ToString() : instance.WorkTaskId;
                SqlParameter WorkFlowInsId = new SqlParameter("@WorkFlowInsId", SqlDbType.NVarChar, 50);
                WorkFlowInsId.Direction = ParameterDirection.Input;
                WorkFlowInsId.Value = instance.WorkFlowInsId == "" ? Guid.Empty.ToString() : instance.WorkFlowInsId;
                SqlParameter WorkTaskInsId = new SqlParameter("@WorkTaskInsId", SqlDbType.NVarChar, 50);
                WorkTaskInsId.Direction = ParameterDirection.Input;
                WorkTaskInsId.Value = instance.WorkTaskInsId == "" ? Guid.Empty.ToString() : instance.WorkTaskInsId;

                SqlParameter CustomerMgr = new SqlParameter("@CustomerMgr", SqlDbType.UniqueIdentifier, 50);
                CustomerMgr.Direction = ParameterDirection.Input;
                CustomerMgr.Value = instance.CustomerMgr;
                SqlParameter CustomerDirector = new SqlParameter("@CustomerDirector", SqlDbType.UniqueIdentifier, 50);
                CustomerDirector.Direction = ParameterDirection.Input;
                CustomerDirector.Value = instance.CustomerDirector;
                SqlParameter CustomerManager = new SqlParameter("@CustomerManager", SqlDbType.UniqueIdentifier, 50);
                CustomerManager.Direction = ParameterDirection.Input;
                CustomerManager.Value = instance.CustomerManager;


                SqlParameter ProduectList = new SqlParameter("@ProduectList", SqlDbType.NVarChar, 4000);
                ProduectList.Direction = ParameterDirection.Input;
                ProduectList.Value = instance.ProduectList;
                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;


                string strSql = "";
                string strView = this.GetStringFromQueryString("view", "");
                if (strView == "unDone")
                {
                    strSql = db.RunSqlCommand("update CrmDeliverMajorProject set ClassFrontServer='" + instance.ClassFrontServer + "' where Code='" + instance.Code + "'").ToString();
                }
                else
                {
                    _Parameters = new IDataParameter[] { Code,DliverState,ClassFrontServer,AddUser,AddTime, 
                                            WorkFlowId,WorkTaskId,WorkFlowInsId,WorkTaskInsId,
                                            CustomerMgr, CustomerDirector, CustomerManager, ProduectList, ReturnValue};
                    strSql = db.RunProcedureReturnString("sp_AddCrmDeliverMajorProject", _Parameters, out iResult);
                }
                if (strSql == "1")
                {
                    string userId = this.User.LoginName;

                    string msg1 = workFlowServiceClient.Start(userId, WorkFlowId.Value.ToString(), WorkTaskId.Value.ToString(),
                         WorkFlowInsId.Value.ToString(), WorkTaskInsId.Value.ToString(), workFlowServiceClient.GetWorkFlowNO(), "提交", "3", GetStringFromQueryString("cName", "") + "─项目交付申请单", false);
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("新增数据失败!");
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 交付申请单--内训
        /// </summary>
        /// <param name="strEntity"></param>
        /// <param name="strJson"></param>
        private void InsertDeliverTrain(string strEntity, string strJson)
        {
            int iResult = 0;
            IDataParameter[] _Parameters = new IDataParameter[] { };
            DbSql db = new DbSql();
            try
            {
                CrmDeliverTrain instance = (CrmDeliverTrain)Globals.JSonToObject<CrmDeliverTrain>(strJson);
                Globals.SetPropertyValue(instance, "AddUser", this.UserId);
                Globals.SetPropertyValue(instance, "AddTime", System.DateTime.Now);

                SqlParameter Code = new SqlParameter("@Code", SqlDbType.Char, 15);
                Code.Direction = ParameterDirection.Input;
                Code.Value = instance.Code;
                SqlParameter ProductID = new SqlParameter("@ProductID", SqlDbType.UniqueIdentifier, 50);
                ProductID.Direction = ParameterDirection.Input;
                ProductID.Value = instance.exp1 == "" ? Guid.Empty : new Guid(instance.exp1);
                SqlParameter OrderID = new SqlParameter("@OrderID", SqlDbType.UniqueIdentifier, 50);
                OrderID.Direction = ParameterDirection.Input;
                OrderID.Value = instance.exp2 == "" ? Guid.Empty : new Guid(instance.exp2);
                SqlParameter ClassFrontServer = new SqlParameter("@ClassFrontServer", SqlDbType.UniqueIdentifier, 50);
                ClassFrontServer.Direction = ParameterDirection.Input;
                ClassFrontServer.Value = instance.ClassFrontServer;
                SqlParameter IsSingleTrain = new SqlParameter("@IsSingleTrain", SqlDbType.Char, 1);
                IsSingleTrain.Direction = ParameterDirection.Input;
                IsSingleTrain.Value = instance.IsSingleTrain;
                SqlParameter TrainSum = new SqlParameter("@TrainSum", SqlDbType.Decimal, 18);
                TrainSum.Direction = ParameterDirection.Input;
                TrainSum.Value = instance.TrainSum;

                SqlParameter AddUser = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
                AddUser.Direction = ParameterDirection.Input;
                AddUser.Value = instance.AddUser;
                SqlParameter DliverState = new SqlParameter("@DliverState", SqlDbType.UniqueIdentifier, 50);
                DliverState.Direction = ParameterDirection.Input;
                DliverState.Value = instance.DliverState;
                SqlParameter AddTime = new SqlParameter("@AddTime", SqlDbType.DateTime, 50);
                AddTime.Direction = ParameterDirection.Input;
                AddTime.Value = instance.AddTime;
                SqlParameter WorkFlowId = new SqlParameter("@WorkFlowId", SqlDbType.NVarChar, 50);
                WorkFlowId.Direction = ParameterDirection.Input;
                WorkFlowId.Value = instance.WorkFlowId;
                SqlParameter WorkTaskId = new SqlParameter("@WorkTaskId", SqlDbType.NVarChar, 50);
                WorkTaskId.Direction = ParameterDirection.Input;
                WorkTaskId.Value = instance.WorkTaskId;
                SqlParameter WorkFlowInsId = new SqlParameter("@WorkFlowInsId", SqlDbType.NVarChar, 50);
                WorkFlowInsId.Direction = ParameterDirection.Input;
                WorkFlowInsId.Value = instance.WorkFlowInsId;
                SqlParameter WorkTaskInsId = new SqlParameter("@WorkTaskInsId", SqlDbType.NVarChar, 50);
                WorkTaskInsId.Direction = ParameterDirection.Input;
                WorkTaskInsId.Value = instance.WorkTaskInsId;

                SqlParameter CustomerMgr = new SqlParameter("@CustomerMgr", SqlDbType.UniqueIdentifier, 50);
                CustomerMgr.Direction = ParameterDirection.Input;
                CustomerMgr.Value = instance.CustomerMgr;
                SqlParameter CustomerDirector = new SqlParameter("@CustomerDirector", SqlDbType.UniqueIdentifier, 50);
                CustomerDirector.Direction = ParameterDirection.Input;
                CustomerDirector.Value = instance.CustomerDirector;
                SqlParameter CustomerManager = new SqlParameter("@CustomerManager", SqlDbType.UniqueIdentifier, 50);
                CustomerManager.Direction = ParameterDirection.Input;
                CustomerManager.Value = instance.CustomerManager;

                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;
                string strSql = "";
                string strView = this.GetStringFromQueryString("view", "");
                if (strView == "unDone")
                {
                    string tempSql = "";
                    if (instance.ClassFrontServer != Guid.Empty)
                    {
                        tempSql = " ClassFrontServer='" + instance.ClassFrontServer + "',IsSingleTrain='" + instance.IsSingleTrain + "',TrainSum=" + instance.TrainSum;
                    }
                    else
                    {
                        tempSql = " IsSingleTrain='" + instance.IsSingleTrain + "',TrainSum=" + instance.TrainSum;
                    }
                    strSql = db.RunSqlCommand("update CrmDeliverTrain set" + tempSql + " where Code='" + instance.Code + "'").ToString();
                }
                else
                {
                    _Parameters = new IDataParameter[] { Code,ProductID,OrderID,ClassFrontServer,IsSingleTrain,TrainSum,AddUser,AddTime, 
                                            WorkFlowId,WorkTaskId,WorkFlowInsId,WorkTaskInsId,DliverState,CustomerMgr,CustomerDirector,CustomerManager,ReturnValue};
                    strSql = db.RunProcedureReturnString("sp_AddCrmDeliverTrain", _Parameters, out iResult);
                }
                if (strSql == "1")
                {
                    string userId = this.User.LoginName;

                    string msg1 = workFlowServiceClient.Start(userId, WorkFlowId.Value.ToString(), WorkTaskId.Value.ToString(),
                         WorkFlowInsId.Value.ToString(), WorkTaskInsId.Value.ToString(), workFlowServiceClient.GetWorkFlowNO(), "提交", "3", GetStringFromQueryString("cName", "") + "─内训交付申请单", false);
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("操作失败!");
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 价值业绩申请单
        /// </summary>
        /// <param name="strEntity"></param>
        /// <param name="strJson"></param>
        private void InsertCrmValue(string strEntity, string strJson)
        {
            int iResult = 0;
            IDataParameter[] _Parameters = new IDataParameter[] { };
            DbSql db = new DbSql();
            try
            {
                CrmValue instance = (CrmValue)Globals.JSonToObject<CrmValue>(strJson);
                Globals.SetPropertyValue(instance, "AddUser", this.UserId);
                SqlParameter ID = new SqlParameter("@ID", SqlDbType.UniqueIdentifier, 50);
                ID.Direction = ParameterDirection.Input;
                ID.Value = instance.ID;
                SqlParameter CustomerID = new SqlParameter("@CustomerID", SqlDbType.UniqueIdentifier, 50);
                CustomerID.Direction = ParameterDirection.Input;
                CustomerID.Value = instance.CustomerID;
                SqlParameter TaskShare = new SqlParameter("@TaskShare", SqlDbType.NVarChar, 2000);
                TaskShare.Direction = ParameterDirection.Input;
                TaskShare.Value = instance.TaskShare;
                SqlParameter TaskExplain = new SqlParameter("@TaskExplain", SqlDbType.NVarChar, 200);
                TaskExplain.Direction = ParameterDirection.Input;
                TaskExplain.Value = instance.TaskExplain;
                SqlParameter ValueType = new SqlParameter("@ValueType", SqlDbType.Char, 1);
                ValueType.Direction = ParameterDirection.Input;
                ValueType.Value = instance.ValueType;
                SqlParameter IsClassSign = new SqlParameter("@IsClassSign", SqlDbType.Char, 1);
                IsClassSign.Direction = ParameterDirection.Input;
                IsClassSign.Value = instance.IsClassSign;
                SqlParameter DevType = new SqlParameter("@DevType", SqlDbType.Char, 1);
                DevType.Direction = ParameterDirection.Input;
                DevType.Value = instance.DevType;
                SqlParameter IsTrainAgain = new SqlParameter("@IsTrainAgain", SqlDbType.Char, 1);
                IsTrainAgain.Direction = ParameterDirection.Input;
                IsTrainAgain.Value = instance.IsTrainAgain;
                SqlParameter IsPayOrder = new SqlParameter("@IsPayOrder", SqlDbType.Char, 1);
                IsPayOrder.Direction = ParameterDirection.Input;
                IsPayOrder.Value = instance.IsPayOrder;
                SqlParameter IsClassCEO = new SqlParameter("@IsClassCEO", SqlDbType.Char, 1);
                IsClassCEO.Direction = ParameterDirection.Input;
                IsClassCEO.Value = instance.IsClassCEO;
                SqlParameter IsWestPoint = new SqlParameter("@IsWestPoint", SqlDbType.Char, 1);
                IsWestPoint.Direction = ParameterDirection.Input;
                IsWestPoint.Value = instance.IsWestPoint;
                SqlParameter IsSalon = new SqlParameter("@IsSalon", SqlDbType.Char, 1);
                IsSalon.Direction = ParameterDirection.Input;
                IsSalon.Value = instance.IsSalon;
                SqlParameter EPIsClassSign = new SqlParameter("@EPIsClassSign", SqlDbType.Char, 1);
                EPIsClassSign.Direction = ParameterDirection.Input;
                EPIsClassSign.Value = instance.EPIsClassSign;
                SqlParameter EPClassPay = new SqlParameter("@EPClassPay", SqlDbType.Char, 1);
                EPClassPay.Direction = ParameterDirection.Input;
                EPClassPay.Value = instance.EPClassPay;
                SqlParameter EPMoney = new SqlParameter("@EPMoney", SqlDbType.Decimal, 18);
                EPMoney.Direction = ParameterDirection.Input;
                EPMoney.Value = instance.EPMoney;
                SqlParameter DevCustomerType = new SqlParameter("@DevCustomerType", SqlDbType.NVarChar, 100);
                DevCustomerType.Direction = ParameterDirection.Input;
                DevCustomerType.Value = instance.DevCustomerType;
                SqlParameter ProductList = new SqlParameter("@ProductList", SqlDbType.NVarChar, 200);
                ProductList.Direction = ParameterDirection.Input;
                ProductList.Value = instance.ProductList;
                SqlParameter SaleRoad = new SqlParameter("@SaleRoad", SqlDbType.NVarChar, 200);
                SaleRoad.Direction = ParameterDirection.Input;
                SaleRoad.Value = instance.SaleRoad;
                SqlParameter Amount = new SqlParameter("@Amount", SqlDbType.NVarChar, 50);
                Amount.Direction = ParameterDirection.Input;
                Amount.Value = instance.Amount;
                SqlParameter LongDateAddress = new SqlParameter("@LongDateAddress", SqlDbType.NVarChar, 50);
                LongDateAddress.Direction = ParameterDirection.Input;
                LongDateAddress.Value = instance.LongDateAddress;
                SqlParameter PayMoneyTotal = new SqlParameter("@PayMoneyTotal", SqlDbType.Decimal, 18);
                PayMoneyTotal.Direction = ParameterDirection.Input;
                PayMoneyTotal.Value = instance.PayMoneyTotal;
                SqlParameter DevCustomerName = new SqlParameter("@DevCustomerName", SqlDbType.NVarChar, 100);
                DevCustomerName.Direction = ParameterDirection.Input;
                DevCustomerName.Value = instance.DevCustomerName;
                SqlParameter TrainDateAddress = new SqlParameter("@TrainDateAddress", SqlDbType.NVarChar, 100);
                TrainDateAddress.Direction = ParameterDirection.Input;
                TrainDateAddress.Value = instance.TrainDateAddress;
                SqlParameter CEODateAddress = new SqlParameter("@CEODateAddress", SqlDbType.NVarChar, 100);
                CEODateAddress.Direction = ParameterDirection.Input;
                CEODateAddress.Value = instance.CEODateAddress;
                SqlParameter UnSignClassReason = new SqlParameter("@UnSignClassReason", SqlDbType.NVarChar, 200);
                UnSignClassReason.Direction = ParameterDirection.Input;
                UnSignClassReason.Value = instance.UnSignClassReason;
                SqlParameter EPDateAddress = new SqlParameter("@EPDateAddress", SqlDbType.NVarChar, 100);
                EPDateAddress.Direction = ParameterDirection.Input;
                EPDateAddress.Value = instance.EPDateAddress;
                SqlParameter EXP1 = new SqlParameter("@EXP1", SqlDbType.NVarChar, 100);
                EXP1.Direction = ParameterDirection.Input;
                EXP1.Value = instance.EXP1;
                SqlParameter EXP2 = new SqlParameter("@EXP2", SqlDbType.NVarChar, 100);
                EXP2.Direction = ParameterDirection.Input;
                EXP2.Value = instance.EXP2;
                SqlParameter EXP3 = new SqlParameter("@EXP3", SqlDbType.NVarChar, 100);
                EXP3.Direction = ParameterDirection.Input;
                EXP3.Value = instance.EXP3;
                SqlParameter EXP4 = new SqlParameter("@EXP4", SqlDbType.NVarChar, 100);
                EXP4.Direction = ParameterDirection.Input;
                EXP4.Value = instance.EXP4;
                SqlParameter AgainBuyDate = new SqlParameter("@AgainBuyDate", SqlDbType.NVarChar, 50);
                AgainBuyDate.Direction = ParameterDirection.Input;
                AgainBuyDate.Value = instance.AgainBuyDate;
                SqlParameter AgainBuyProduct = new SqlParameter("@AgainBuyProduct", SqlDbType.NVarChar, 200);
                AgainBuyProduct.Direction = ParameterDirection.Input;
                AgainBuyProduct.Value = instance.AgainBuyProduct;
                SqlParameter AddUser = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
                AddUser.Direction = ParameterDirection.Input;
                AddUser.Value = instance.AddUser;
                SqlParameter EPPayDate = new SqlParameter("@EPPayDate", SqlDbType.NVarChar, 50);
                EPPayDate.Direction = ParameterDirection.Input;
                EPPayDate.Value = instance.EPPayDate;
                SqlParameter FirstDate = new SqlParameter("@FirstDate", SqlDbType.NVarChar, 50);
                FirstDate.Direction = ParameterDirection.Input;
                FirstDate.Value = instance.FirstDate;
                SqlParameter FirstNum = new SqlParameter("@FirstNum", SqlDbType.NVarChar, 50);
                FirstNum.Direction = ParameterDirection.Input;
                FirstNum.Value = instance.FirstNum;
                SqlParameter LastCEO = new SqlParameter("@LastCEO", SqlDbType.Char, 1);
                LastCEO.Direction = ParameterDirection.Input;
                LastCEO.Value = instance.LastCEO;
                SqlParameter CEOAddress = new SqlParameter("@CEOAddress", SqlDbType.NVarChar, 50);
                CEOAddress.Direction = ParameterDirection.Input;
                CEOAddress.Value = instance.CEOAddress;
                SqlParameter LastAddress = new SqlParameter("@LastAddress", SqlDbType.NVarChar, 50);
                LastAddress.Direction = ParameterDirection.Input;
                LastAddress.Value = instance.LastAddress;
                SqlParameter FactTempDate = new SqlParameter("@FactTempDate", SqlDbType.NVarChar, 200);
                FactTempDate.Direction = ParameterDirection.Input;
                FactTempDate.Value = instance.FactTempDate;
                SqlParameter OrderMoney = new SqlParameter("@OrderMoney", SqlDbType.NVarChar, 50);
                OrderMoney.Direction = ParameterDirection.Input;
                OrderMoney.Value = instance.OrderMoney;
                SqlParameter APDate = new SqlParameter("@APDate", SqlDbType.DateTime, 50);
                APDate.Direction = ParameterDirection.Input;
                APDate.Value = instance.APDate;
                SqlParameter WorkFlowId = new SqlParameter("@WorkFlowId", SqlDbType.NVarChar, 50);
                WorkFlowId.Direction = ParameterDirection.Input;
                WorkFlowId.Value = instance.WorkFlowId;
                SqlParameter WorkTaskId = new SqlParameter("@WorkTaskId", SqlDbType.NVarChar, 50);
                WorkTaskId.Direction = ParameterDirection.Input;
                WorkTaskId.Value = instance.WorkTaskId;
                SqlParameter WorkFlowInsId = new SqlParameter("@WorkFlowInsId", SqlDbType.NVarChar, 50);
                WorkFlowInsId.Direction = ParameterDirection.Input;
                WorkFlowInsId.Value = instance.WorkFlowInsId;
                SqlParameter WorkTaskInsId = new SqlParameter("@WorkTaskInsId", SqlDbType.NVarChar, 50);
                WorkTaskInsId.Direction = ParameterDirection.Input;
                WorkTaskInsId.Value = instance.WorkTaskInsId;
                SqlParameter CName = new SqlParameter("@CName", SqlDbType.UniqueIdentifier, 50);
                CName.Direction = ParameterDirection.Input;
                CName.Value = instance.CName;
                SqlParameter CZName = new SqlParameter("@CZName", SqlDbType.UniqueIdentifier, 50);
                CZName.Direction = ParameterDirection.Input;
                CZName.Value = instance.CZName;
                SqlParameter CTel = new SqlParameter("@CTel", SqlDbType.NVarChar, 50);
                CTel.Direction = ParameterDirection.Input;
                CTel.Value = instance.CTel;
                SqlParameter CZTel = new SqlParameter("@CZTel", SqlDbType.NVarChar, 50);
                CZTel.Direction = ParameterDirection.Input;
                CZTel.Value = instance.CZTel;
                SqlParameter payId = new SqlParameter("@payId", SqlDbType.NVarChar, 500);
                payId.Direction = ParameterDirection.Input;
                payId.Value = GetStringFromQueryString("payId", "");
                SqlParameter DliverState = new SqlParameter("@DliverState", SqlDbType.UniqueIdentifier, 50);
                DliverState.Direction = ParameterDirection.Input;
                DliverState.Value = instance.DliverState;
                SqlParameter OneMoney = new SqlParameter("@OneMoney", SqlDbType.NVarChar, 500);
                OneMoney.Direction = ParameterDirection.Input;
                OneMoney.Value = instance.OneMoney;
                SqlParameter ProjectMoney = new SqlParameter("@ProjectMoney", SqlDbType.Decimal, 18);
                ProjectMoney.Direction = ParameterDirection.Input;
                ProjectMoney.Value = instance.ProjectMoney;
                SqlParameter ProjectType = new SqlParameter("@ProjectType", SqlDbType.UniqueIdentifier, 50);
                ProjectType.Direction = ParameterDirection.Input;
                ProjectType.Value = instance.ProjectType;
                SqlParameter IsCOProject = new SqlParameter("@IsCOProject", SqlDbType.Char, 1);
                IsCOProject.Direction = ParameterDirection.Input;
                IsCOProject.Value = instance.IsCOProject;
                SqlParameter IsFirstSale = new SqlParameter("@IsFirstSale", SqlDbType.Char, 1);
                IsFirstSale.Direction = ParameterDirection.Input;
                IsFirstSale.Value = instance.IsFirstSale;
                SqlParameter PackName = new SqlParameter("@PackName", SqlDbType.NVarChar, 50);
                PackName.Direction = ParameterDirection.Input;
                PackName.Value = instance.PackName;
                SqlParameter DevYear = new SqlParameter("@DevYear", SqlDbType.NVarChar, 10);
                DevYear.Direction = ParameterDirection.Input;
                DevYear.Value = instance.DevYear;
                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;
                string strSql = "";
                _Parameters = new IDataParameter[] {ID,
								CustomerID,ValueType,
								TaskShare,
								TaskExplain,
								DevType,
								DevCustomerName,
								DevCustomerType,
								IsTrainAgain,
								AddUser,
								APDate,
								TrainDateAddress,
								IsClassSign,
								IsPayOrder,
								IsClassCEO,
								CEODateAddress,
								IsWestPoint,
								IsSalon,
								UnSignClassReason,
								EPIsClassSign,
								EPDateAddress,
								EPClassPay,
								EPPayDate,
								EPMoney, ProductList,SaleRoad,Amount, PayMoneyTotal,LongDateAddress,
                                FirstDate, FirstNum,LastCEO,CEOAddress,LastAddress,FactTempDate,OrderMoney,EXP1,EXP2,EXP3,EXP4,AgainBuyDate, AgainBuyProduct,
								WorkFlowId,
								WorkTaskId,
								WorkFlowInsId,
								WorkTaskInsId,CName,CTel,CZName,CZTel,payId,DliverState,IsFirstSale,OneMoney,IsCOProject,
ProjectType ,
ProjectMoney,PackName,DevYear, ReturnValue};
                strSql = db.RunProcedureReturnString("sp_AddCrmValue", _Parameters, out iResult);

                if (strSql == "1")
                {
                    string userId = this.User.LoginName;

                    string msg1 = workFlowServiceClient.Start(userId, WorkFlowId.Value.ToString(), WorkTaskId.Value.ToString(),
                         WorkFlowInsId.Value.ToString(), WorkTaskInsId.Value.ToString(), workFlowServiceClient.GetWorkFlowNO(), "提交", "3", GetStringFromQueryString("cName", "") + "─价值业绩申请单", false);
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("操作失败!");
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 交付申请单--英才学校
        /// </summary>
        /// <param name="strEntity"></param>
        /// <param name="strJson"></param>
        private void InsertDeliverHr(string strEntity, string strJson)
        {
            int iResult = 0;
            IDataParameter[] _Parameters = new IDataParameter[] { };
            IDataParameter[] _ParametersUpdate = new IDataParameter[] { };
            DbSql db = new DbSql();
            try
            {
                CrmDeliverHr instance = (CrmDeliverHr)Globals.JSonToObject<CrmDeliverHr>(strJson);
                Globals.SetPropertyValue(instance, "AddUser", this.UserId);
                Globals.SetPropertyValue(instance, "AddTime", System.DateTime.Now);

                SqlParameter Code = new SqlParameter("@Code", SqlDbType.Char, 15);
                Code.Direction = ParameterDirection.Input;
                Code.Value = instance.Code;
                SqlParameter ProductID = new SqlParameter("@ProductIDs", SqlDbType.UniqueIdentifier, 50);
                ProductID.Direction = ParameterDirection.Input;
                ProductID.Value = this.GetStringFromQueryString("productId", "") == "" ? Guid.Empty : new Guid(this.GetStringFromQueryString("productId", ""));
                SqlParameter OrderID = new SqlParameter("@OrderID", SqlDbType.UniqueIdentifier, 50);
                OrderID.Direction = ParameterDirection.Input;
                OrderID.Value = this.GetStringFromQueryString("orderPid", "") == "" ? Guid.Empty : new Guid(this.GetStringFromQueryString("orderPid", ""));
                SqlParameter ClassFrontServer = new SqlParameter("@ClassFrontServer", SqlDbType.UniqueIdentifier, 50);
                ClassFrontServer.Direction = ParameterDirection.Input;
                ClassFrontServer.Value = instance.ClassFrontServer;
                SqlParameter IsDealEP = new SqlParameter("@IsDealEP", SqlDbType.Char, 1);
                IsDealEP.Direction = ParameterDirection.Input;
                IsDealEP.Value = instance.IsDealEP;

                SqlParameter ID = new SqlParameter("@ID", SqlDbType.UniqueIdentifier, 50);
                ID.Direction = ParameterDirection.Input;
                ID.Value = instance.ID;
                SqlParameter AddUser = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
                AddUser.Direction = ParameterDirection.Input;
                AddUser.Value = instance.AddUser;
                SqlParameter TermId = new SqlParameter("@TermId", SqlDbType.UniqueIdentifier, 50);
                TermId.Direction = ParameterDirection.Input;
                TermId.Value = instance.TermId;
                SqlParameter DliverState = new SqlParameter("@DliverState", SqlDbType.UniqueIdentifier, 50);
                DliverState.Direction = ParameterDirection.Input;
                DliverState.Value = instance.DliverState;//@TermId uniqueidentifier,
                SqlParameter AddTime = new SqlParameter("@AddTime", SqlDbType.DateTime, 50);
                AddTime.Direction = ParameterDirection.Input;
                AddTime.Value = instance.AddTime;
                SqlParameter Email = new SqlParameter("@Email", SqlDbType.NVarChar, 50);
                Email.Direction = ParameterDirection.Input;
                Email.Value = instance.Email;
                SqlParameter WorkFlowId = new SqlParameter("@WorkFlowId", SqlDbType.NVarChar, 50);
                WorkFlowId.Direction = ParameterDirection.Input;
                WorkFlowId.Value = instance.WorkFlowId;
                SqlParameter WorkTaskId = new SqlParameter("@WorkTaskId", SqlDbType.NVarChar, 50);
                WorkTaskId.Direction = ParameterDirection.Input;
                WorkTaskId.Value = instance.WorkTaskId;
                SqlParameter ConsultPerson = new SqlParameter("@ConsultPerson", SqlDbType.NVarChar, 30); //接洽人
                ConsultPerson.Direction = ParameterDirection.Input;
                ConsultPerson.Value = GetStringFromQueryString("linkman", "");
                SqlParameter ConsultPersonTel = new SqlParameter("@ConsultPersonTel", SqlDbType.NVarChar, 30);  //接洽人电话
                ConsultPersonTel.Direction = ParameterDirection.Input;
                ConsultPersonTel.Value = GetStringFromQueryString("linkmanTel", "");
                SqlParameter MgrTel = new SqlParameter("@MgrTel", SqlDbType.NVarChar, 30); //客户经理电话
                MgrTel.Direction = ParameterDirection.Input;
                MgrTel.Value = GetStringFromQueryString("mgrTel", "");
                SqlParameter Explain = new SqlParameter("@Explains", SqlDbType.NVarChar, 50);
                Explain.Direction = ParameterDirection.Input;
                Explain.Value = instance.Explain;
                SqlParameter WorkFlowInsId = new SqlParameter("@WorkFlowInsId", SqlDbType.NVarChar, 50);
                WorkFlowInsId.Direction = ParameterDirection.Input;
                WorkFlowInsId.Value = instance.WorkFlowInsId;
                SqlParameter WorkTaskInsId = new SqlParameter("@WorkTaskInsId", SqlDbType.NVarChar, 50);
                WorkTaskInsId.Direction = ParameterDirection.Input;
                WorkTaskInsId.Value = instance.WorkTaskInsId;

                SqlParameter StudentList = new SqlParameter("@StudentList", SqlDbType.NVarChar, 8000);
                StudentList.Direction = ParameterDirection.Input;
                StudentList.Value = instance.StudentList;
                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;
                string strSql = "";
                string strView = this.GetStringFromQueryString("view", "");
                if (strView == "unDone")
                {
                    string tempSql = "update CrmDeliverHr set ";
                    if (instance.ClassFrontServer != Guid.Empty)
                    {
                        tempSql += " ClassFrontServer='" + instance.ClassFrontServer + "',ConsultPerson='" + CSVHelper.FmSQL(GetStringFromQueryString("linkman", "")) + "',IsDealEP='" + instance.IsDealEP + "',ConsultPersonTel='" + CSVHelper.FmSQL(GetStringFromQueryString("linkmanTel", "")) + "',MgrTel='" + CSVHelper.FmSQL(GetStringFromQueryString("mgrTel", "")) + "',Email='" + Email.Value + "',Explain='" + CSVHelper.FmSQL(Explain.Value) + "'";
                    }
                    else
                    {
                        tempSql += " ConsultPerson='" + CSVHelper.FmSQL(GetStringFromQueryString("linkman", "")) + "',IsDealEP='" + instance.IsDealEP + "',ConsultPersonTel='" + CSVHelper.FmSQL(GetStringFromQueryString("linkmanTel", "")) + "',Email='" + Email.Value + "', MgrTel='" + GetStringFromQueryString("mgrTel", "") + "',Explain='" + CSVHelper.FmSQL(Explain.Value) + "'";
                    }
                    SqlParameter _temSqls = new SqlParameter("@temSqls", SqlDbType.NVarChar, 800);
                    _temSqls.Direction = ParameterDirection.Input;
                    _temSqls.Value = tempSql + " where Code='" + instance.Code + "'";
                    _ParametersUpdate = new IDataParameter[] { _temSqls, StudentList, ReturnValue };
                    strSql = db.RunProcedureReturnString("sp_UpdateCrmDeliverHr", _ParametersUpdate, out iResult);
                }
                else
                {
                    _Parameters = new IDataParameter[] { ID, Code, ProductID, OrderID, ClassFrontServer, MgrTel, ConsultPerson, ConsultPersonTel, Email, IsDealEP, Explain, AddUser, AddTime, DliverState, WorkFlowId, WorkTaskId, WorkFlowInsId, WorkTaskInsId, TermId, StudentList, ReturnValue };
                    strSql = db.RunProcedureReturnString("sp_AddCrmDeliverHr", _Parameters, out iResult);
                }
                if (strSql == "1")
                {
                    string userId = this.User.LoginName;

                    string msg1 = workFlowServiceClient.Start(userId, WorkFlowId.Value.ToString(), WorkTaskId.Value.ToString(),
                         WorkFlowInsId.Value.ToString(), WorkTaskInsId.Value.ToString(), workFlowServiceClient.GetWorkFlowNO(), "提交", "3", GetStringFromQueryString("cName", "") + "─英才学校交付申请单", false);
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write(ReturnValue.Value);
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 保存联系人信息
        /// </summary>
        /// <param name="strEntity"></param>
        /// <param name="strJson"></param>
        private void InsertCrmLinkMan(string strEntity, string strJson)
        {
            try
            {
                CrmLinkMan instance = (CrmLinkMan)Globals.JSonToObject<CrmLinkMan>(strJson);
                Globals.SetPropertyValue(instance, "AddUser", this.UserId);
                Globals.SetPropertyValue(instance, "AddTime", System.DateTime.Now);

                string strSqls = string.Format("Exec sp_AddCrmLinkMan '{0}','{1}','{2}','{3}','{4}','{5}','{6}'," +
                                                "'{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}'",
                                                    instance.ID, instance.Code, instance.Caption, instance.CustomId,
                                                    instance.TypeID, instance.Sex, instance.Position, instance.DeptName,
                                                    instance.MobileTel, instance.Email,
                                                    instance.Homeplace, instance.BirthdayType, "1900-01-01",
                                                    instance.LinkManFancy, instance.EXP1, instance.EXP2, instance.Drink,
                                                    instance.Relation, instance.AddUser, instance.AddTime, 0);
                int iResults = bll.RunSqlCommand(strSqls);
                if (iResults > 0)
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("0");
                }
            }
            catch
            {
                HttpContext.Current.Response.Write("0");
            }
        }
        /// <summary>
        /// 保存行销中心记录
        /// </summary>
        /// <param name="strEntity"></param>
        /// <param name="strJson"></param>
        private void InsertCrmActivity(string strEntity, string strJson)
        {
            int iResult = 0;
            IDataParameter[] _Parameters = new IDataParameter[] { };
            DbSql db = new DbSql();
            try
            {
                CrmActivity instance = (CrmActivity)Globals.JSonToObject<CrmActivity>(strJson);
                Globals.SetPropertyValue(instance, "AddUser", this.UserId);
                Globals.SetPropertyValue(instance, "AddTime", System.DateTime.Now);

                SqlParameter ID = new SqlParameter("@ID", SqlDbType.UniqueIdentifier, 50);
                ID.Direction = ParameterDirection.Input;
                ID.Value = instance.ID;
                SqlParameter Code = new SqlParameter("@Code", SqlDbType.Char, 15);
                Code.Direction = ParameterDirection.Input;
                Code.Value = ZX.BLL.IDMaker.GetSequenceStr("CUS003");
                SqlParameter Caption = new SqlParameter("@Caption", SqlDbType.NVarChar, 30);
                Caption.Direction = ParameterDirection.Input;
                Caption.Value = instance.Caption;
                SqlParameter CustomId = new SqlParameter("@CustomId", SqlDbType.UniqueIdentifier, 50);
                CustomId.Direction = ParameterDirection.Input;
                CustomId.Value = instance.CustomId;
                SqlParameter TypeId = new SqlParameter("@TypeId", SqlDbType.UniqueIdentifier, 50);
                TypeId.Direction = ParameterDirection.Input;
                TypeId.Value = instance.TypeId;
                SqlParameter LinkManID = new SqlParameter("@LinkManID", SqlDbType.UniqueIdentifier, 50);
                LinkManID.Direction = ParameterDirection.Input;
                LinkManID.Value = instance.LinkManID;
                SqlParameter PlanStartDate = new SqlParameter("@PlanStartDate", SqlDbType.DateTime, 50);
                PlanStartDate.Direction = ParameterDirection.Input;
                PlanStartDate.Value = instance.PlanStartDate;
                SqlParameter PlanEndDate = new SqlParameter("@PlanEndDate", SqlDbType.DateTime, 50);
                PlanEndDate.Direction = ParameterDirection.Input;
                PlanEndDate.Value = instance.PlanEndDate;
                SqlParameter Contents = new SqlParameter("@Contents", SqlDbType.NVarChar, 500);
                Contents.Direction = ParameterDirection.Input;
                Contents.Value = instance.Contents;
                SqlParameter Explain = new SqlParameter("@Explain", SqlDbType.NVarChar, 200);
                Explain.Direction = ParameterDirection.Input;
                Explain.Value = instance.Explain;
                SqlParameter AddUser = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
                AddUser.Direction = ParameterDirection.Input;
                AddUser.Value = instance.AddUser;
                SqlParameter AddTime = new SqlParameter("@AddTime", SqlDbType.DateTime, 50);
                AddTime.Direction = ParameterDirection.Input;
                AddTime.Value = instance.AddTime;
                SqlParameter AnticipeResult = new SqlParameter("@AnticipeResult", SqlDbType.NVarChar, 500);
                AnticipeResult.Direction = ParameterDirection.Input;
                SqlParameter Result = new SqlParameter("@Result", SqlDbType.NVarChar, 500);
                Result.Direction = ParameterDirection.Input;
                if (strEntity == "CrmActivity")
                {
                    AnticipeResult.Value = "";
                    Result.Value = "";
                }
                else if (strEntity == "CrmActivityInfo")
                {
                    AnticipeResult.Value = instance.AnticipeResult;
                    Result.Value = instance.Result;
                }
                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;

                _Parameters = new IDataParameter[] { ID, Code, Caption, CustomId, TypeId, LinkManID, PlanStartDate, PlanEndDate, Contents, Explain, AddUser, AddTime, AnticipeResult, Result, ReturnValue };
                string strSql = db.RunProcedureReturnString("sp_AddCrmActivity", _Parameters, out iResult);
                if (strSql == "1")
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write(strSql);
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }

            /*try
            {
                CrmActivity instance = (CrmActivity)Globals.JSonToObject<CrmActivity>(strJson);
                Globals.SetPropertyValue(instance, "AddUser", this.UserId);
                Globals.SetPropertyValue(instance, "AddTime", System.DateTime.Now);

                string strSqls = "";
                if (strEntity == "CrmActivity")
                {
                    strSqls = string.Format("Exec sp_AddCrmActivity '{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}'",
                                                instance.ID, ZX.BLL.IDMaker.GetSequenceStr("CUS003"),
                                                instance.Caption, instance.CustomId, instance.TypeId,
                                                instance.LinkManID, instance.PlanStartDate, instance.PlanEndDate,
                                                instance.Contents, instance.Explain, instance.AddUser,
                                                instance.AddTime, "", "");
                }
                else if (strEntity == "CrmActivityInfo")
                {
                    strSqls = string.Format("Exec sp_AddCrmActivity '{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}'",
                                                instance.ID, ZX.BLL.IDMaker.GetSequenceStr("CUS003"),
                                                instance.Caption, instance.CustomId, instance.TypeId,
                                                instance.LinkManID, instance.PlanStartDate, instance.PlanEndDate,
                                                instance.Contents, instance.Explain, instance.AddUser,
                                                instance.AddTime, instance.AnticipeResult, instance.Result);
                }
                int iResults = bll.RunSqlCommand(strSqls);
                if (iResults > 0)
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("0");
                }
            }
            catch
            {
                HttpContext.Current.Response.Write("0");
            }*/
        }
        /// <summary>
        /// 客户修改保存修改日志
        /// </summary>
        /// <param name="strEntity"></param>
        /// <param name="strJson"></param>
        private void InsertCrmCustomerOperator(string strEntity, string strJson)
        {
            try
            {
                string strCustomerId = this.GetStringFromQueryString("id", ""); //客户ID
                string strSqls = string.Format("Exec sp_AddCrmCustomerOperator '{0}','{1}','{2}','{3}','{4}','{5}'",
                                                    this.UserId, new Guid(strCustomerId), strJson,
                                                    "客户修改日志记录", this.UserId, DateTime.Now.ToString());
                int iResults = bll.RunSqlCommand(strSqls);
                if (iResults > 0)
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("0");
                }
            }
            catch
            {
                HttpContext.Current.Response.Write("0");
            }
        }
        /// <summary>
        /// 插入客户关系数据
        /// </summary>
        /// <param name="strEntity"></param>
        /// <param name="strJson"></param>
        private void InsertCrmCustomerRelation(string strEntity, string strJson)
        {
            try
            {
                CrmCustomerRelation instance = (CrmCustomerRelation)Globals.JSonToObject<CrmCustomerRelation>(strJson);
                Globals.SetPropertyValue(instance, "AddUser", this.UserId);
                Globals.SetPropertyValue(instance, "AddTime", System.DateTime.Now);
                string strRelationId = this.GetStringFromQueryString("rid", "");
                string strSql = "";
                if (strRelationId == "") //新增
                {
                    strSql = string.Format("insert into CrmCustomerRelation(CustomerID,RelationCustomerID,RelationCustomerName," +
                                            "CustomerRelation,Explain,AddUser,AddTime) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')",
                                            instance.CustomerID, instance.RelationCustomerID, instance.RelationCustomerName,
                                            instance.CustomerRelation, instance.Explain, instance.AddUser, instance.AddTime);
                }
                else //修改
                {
                    strSql = string.Format("update CrmCustomerRelation set RelationCustomerID='{0}'," +
                                        "RelationCustomerName='{1}',CustomerRelation='{2}',Explain='{3}'," +
                                        "AddUser='{4}',AddTime='{5}' where ID='{6}'",
                                    instance.RelationCustomerID, instance.RelationCustomerName, instance.CustomerRelation,
                                    instance.Explain, instance.AddUser, instance.AddTime, strRelationId);
                }
                DbSql db = new DbSql();
                if (db.RunSqlCommand(strSql) > 0)
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("0");
                }
            }
            catch
            {
                HttpContext.Current.Response.Write("0");
            }
        }
        /// <summary>
        /// 销售订单变更单
        /// </summary>
        /// <param name="strEntity"></param>
        /// <param name="strJson"></param>
        private void InsertCrmOrderModifyOperator(string strEntity, string strJson)
        {
            try
            {
                int iResult = 0;
                IDataParameter[] _Parameters = new IDataParameter[] { };
                DbSql db = new DbSql();

                CrmCustomerOrder instance = (CrmCustomerOrder)Globals.JSonToObject<CrmCustomerOrder>(strJson);
                Globals.SetPropertyValue(instance, "AddUser", this.UserId);
                Globals.SetPropertyValue(instance, "AddTime", System.DateTime.Now);

                SqlParameter ProduectList = new SqlParameter("@ProduectList", SqlDbType.NVarChar, 8000);
                ProduectList.Direction = ParameterDirection.Input;
                ProduectList.Value = instance.ProduectList;
                SqlParameter NewProduectList = new SqlParameter("@NewProduectList", SqlDbType.NVarChar, 8000);
                NewProduectList.Direction = ParameterDirection.Input;
                NewProduectList.Value = instance.NewProduectList;
                SqlParameter AddUser = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
                AddUser.Direction = ParameterDirection.Input;
                AddUser.Value = instance.AddUser;
                SqlParameter AddTime = new SqlParameter("@AddTime", SqlDbType.DateTime, 50);
                AddTime.Direction = ParameterDirection.Input;
                AddTime.Value = instance.AddTime;
                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;

                _Parameters = new IDataParameter[] { ProduectList, NewProduectList, AddUser, AddTime, ReturnValue };
                string strSql = db.RunProcedureReturnString("sp_UpdateCrmOrderModifyOperator", _Parameters, out iResult);
                if (strSql == "1")
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write(strSql);
                }
            }
            catch
            {
                HttpContext.Current.Response.Write("数据异常!保存失败!");
            }
        }
        /// <summary>
        /// 历史数据录入
        /// </summary>
        /// <param name="strEntity"></param>
        /// <param name="strJson"></param>
        private void InsertCustomerHistory(string strEntity, string strJson)
        {
            int iResult = 0;
            IDataParameter[] _Parameters = new IDataParameter[] { };
            DbSql db = new DbSql();
            try
            {
                V_CrmCustomerHistory instance = (V_CrmCustomerHistory)Globals.JSonToObject<V_CrmCustomerHistory>(strJson);
                SqlParameter AddUser = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
                AddUser.Direction = ParameterDirection.Input;
                AddUser.Value = instance.AddUser;
                SqlParameter AddTime = new SqlParameter("@AddTime", SqlDbType.DateTime, 50);
                AddTime.Direction = ParameterDirection.Input;
                AddTime.Value = instance.AddTime;
                SqlParameter SaleadviserId = new SqlParameter("@SaleadviserId", SqlDbType.UniqueIdentifier, 50);
                SaleadviserId.Direction = ParameterDirection.Input;
                SaleadviserId.Value = instance.SaleadviserId;
                SqlParameter CustomerId = new SqlParameter("@CustomerId", SqlDbType.UniqueIdentifier, 50);
                CustomerId.Direction = ParameterDirection.Input;
                CustomerId.Value = instance.ID;
                SqlParameter Code = new SqlParameter("@Code", SqlDbType.NVarChar, 50);
                Code.Direction = ParameterDirection.Input;
                Code.Value = instance.Code;
                SqlParameter State = new SqlParameter("@State", SqlDbType.NVarChar, 50);
                State.Direction = ParameterDirection.Input;
                State.Value = instance.State;
                SqlParameter Province = new SqlParameter("@Province", SqlDbType.NVarChar, 50);
                Province.Direction = ParameterDirection.Input;
                Province.Value = instance.Province;
                SqlParameter City = new SqlParameter("@City", SqlDbType.NVarChar, 50);
                City.Direction = ParameterDirection.Input;
                City.Value = instance.City;
                SqlParameter Area = new SqlParameter("@Area", SqlDbType.NVarChar, 50);
                Area.Direction = ParameterDirection.Input;
                Area.Value = instance.Area;
                SqlParameter Address = new SqlParameter("@Address", SqlDbType.NVarChar, 100);
                Address.Direction = ParameterDirection.Input;
                Address.Value = instance.Address;
                SqlParameter CustomerName = new SqlParameter("@CustomerName", SqlDbType.NVarChar, 50);
                CustomerName.Direction = ParameterDirection.Input;
                CustomerName.Value = instance.CustomerName;
                SqlParameter Decisionmaker = new SqlParameter("@Decisionmaker", SqlDbType.NVarChar, 30);
                Decisionmaker.Direction = ParameterDirection.Input;
                Decisionmaker.Value = instance.Decisionmaker;
                SqlParameter DecisionTel = new SqlParameter("@DecisionTel", SqlDbType.NVarChar, 20);
                DecisionTel.Direction = ParameterDirection.Input;
                DecisionTel.Value = instance.DecisionTel;
                SqlParameter DecisionPosition = new SqlParameter("@DecisionPosition", SqlDbType.NVarChar, 20);
                DecisionPosition.Direction = ParameterDirection.Input;
                DecisionPosition.Value = instance.DecisionPosition;
                SqlParameter DecisionSex = new SqlParameter("@DecisionSex", SqlDbType.Char, 1);
                DecisionSex.Direction = ParameterDirection.Input;
                DecisionSex.Value = instance.DecisionSex;
                SqlParameter CompanyProduct = new SqlParameter("@CompanyProduct", SqlDbType.NVarChar, 100);
                CompanyProduct.Direction = ParameterDirection.Input;
                CompanyProduct.Value = instance.CompanyProduct;
                SqlParameter Tel1 = new SqlParameter("@Tel1", SqlDbType.NVarChar, 20);
                Tel1.Direction = ParameterDirection.Input;
                Tel1.Value = instance.Tel1;
                SqlParameter Tel2 = new SqlParameter("@Tel2", SqlDbType.NVarChar, 20);
                Tel2.Direction = ParameterDirection.Input;
                Tel2.Value = instance.Tel2;
                SqlParameter DecisionEmail = new SqlParameter("@DecisionEmail", SqlDbType.NVarChar, 30);
                DecisionEmail.Direction = ParameterDirection.Input;
                DecisionEmail.Value = instance.DecisionEmail;
                SqlParameter PersonId = new SqlParameter("@PersonId", SqlDbType.UniqueIdentifier, 50);
                PersonId.Direction = ParameterDirection.Input;
                PersonId.Value = instance.PersonId;
                SqlParameter AreaId = new SqlParameter("@AreaId", SqlDbType.UniqueIdentifier, 50);
                AreaId.Direction = ParameterDirection.Input;
                AreaId.Value = instance.AreaId;
                SqlParameter ProductId = new SqlParameter("@ProductId", SqlDbType.UniqueIdentifier, 50);
                ProductId.Direction = ParameterDirection.Input;
                ProductId.Value = instance.ProductId;
                SqlParameter TradeId = new SqlParameter("@TradeId", SqlDbType.UniqueIdentifier, 50);
                TradeId.Direction = ParameterDirection.Input;
                TradeId.Value = instance.TradeId;
                SqlParameter PropertyId = new SqlParameter("@PropertyId", SqlDbType.UniqueIdentifier, 50);
                PropertyId.Direction = ParameterDirection.Input;
                PropertyId.Value = instance.PropertyId;
                SqlParameter LevelId = new SqlParameter("@LevelId", SqlDbType.UniqueIdentifier, 50);
                LevelId.Direction = ParameterDirection.Input;
                LevelId.Value = instance.LevelId;
                SqlParameter CompanyNetting = new SqlParameter("@CompanyNetting", SqlDbType.NVarChar, 30);
                CompanyNetting.Direction = ParameterDirection.Input;
                CompanyNetting.Value = instance.CompanyNetting;
                SqlParameter Email = new SqlParameter("@Email", SqlDbType.NVarChar, 30);
                Email.Direction = ParameterDirection.Input;
                Email.Value = instance.Email;
                SqlParameter TotalMoney = new SqlParameter("@TotalMoney", SqlDbType.Decimal, 20);
                TotalMoney.Direction = ParameterDirection.Input;
                TotalMoney.Value = instance.TotalMoney;
                SqlParameter TeacherId = new SqlParameter("@TeacherId", SqlDbType.UniqueIdentifier, 50);
                TeacherId.Direction = ParameterDirection.Input;
                TeacherId.Value = instance.TeachID;
                SqlParameter TeacherTime = new SqlParameter("@TeacherTime", SqlDbType.DateTime, 50);
                TeacherTime.Direction = ParameterDirection.Input;
                TeacherTime.Value = instance.HmDate;
                SqlParameter TeacherType = new SqlParameter("@TeacherType", SqlDbType.Char, 1);
                TeacherType.Direction = ParameterDirection.Input;
                TeacherType.Value = instance.HmType;
                SqlParameter DeptId = new SqlParameter("@DeptId", SqlDbType.UniqueIdentifier, 50);
                DeptId.Direction = ParameterDirection.Input;
                DeptId.Value = instance.DeptId;
                SqlParameter PersonNumber = new SqlParameter("@PersonNumber", SqlDbType.Int, 10);
                PersonNumber.Direction = ParameterDirection.Input;
                PersonNumber.Value = instance.Amount;
                SqlParameter Rebate = new SqlParameter("@Rebate", SqlDbType.NVarChar, 20);
                Rebate.Direction = ParameterDirection.Input;
                Rebate.Value = instance.Rebate;
                SqlParameter AccountReceivable = new SqlParameter("@AccountReceivable", SqlDbType.Decimal, 20);
                AccountReceivable.Direction = ParameterDirection.Input;
                AccountReceivable.Value = instance.AccountReceivable;
                SqlParameter OrderCode1 = new SqlParameter("@OrderCode1", SqlDbType.NVarChar, 20);
                OrderCode1.Direction = ParameterDirection.Input;
                OrderCode1.Value = IDMaker.GetSequenceStr("BILL001");
                SqlParameter OrderCode2 = new SqlParameter("@OrderCode2", SqlDbType.NVarChar, 20);
                OrderCode2.Direction = ParameterDirection.Input;
                OrderCode2.Value = IDMaker.GetSequenceStr("BILL001");
                SqlParameter UserIds = new SqlParameter("@UserId", SqlDbType.NVarChar, 50);
                UserIds.Direction = ParameterDirection.Input;
                UserIds.Value = this.UserId.ToString();
                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;
                _Parameters = new IDataParameter[] { CustomerId,Code,CustomerName,State,Province,City,Area,Address,
                                                Decisionmaker,DecisionTel,DecisionPosition,DecisionSex,CompanyProduct,
                                                Tel1,Tel2,DecisionEmail,PersonId,AreaId,ProductId,TradeId,PropertyId,
                                                LevelId,CompanyNetting,Email,OrderCode1,OrderCode2,
                                                TotalMoney,TeacherId,TeacherTime,
                                                TeacherType,DeptId,PersonNumber,AccountReceivable,Rebate,AddUser,
                                                SaleadviserId,UserIds,ReturnValue};
                string strSql = db.RunProcedureReturnString("sp_AddCrmCustomerHistory", _Parameters, out iResult);
                if (strSql == "1")
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write(strSql);
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 保存产品包
        /// </summary>
        /// <param name="strEntity"></param>
        /// <param name="strJson"></param>
        private void InsertCrmProductPack(string strEntity, string strJson)
        {
            int iResult = 0;
            IDataParameter[] _Parameters = new IDataParameter[] { };
            DbSql db = new DbSql();
            try
            {
                CrmProductPack instance = (CrmProductPack)Globals.JSonToObject<CrmProductPack>(strJson);
                Globals.SetPropertyValue(instance, "AddUser", this.UserId);
                Globals.SetPropertyValue(instance, "Addtime", System.DateTime.Now);
                SqlParameter ID = new SqlParameter("@PackID", SqlDbType.UniqueIdentifier, 50);
                ID.Direction = ParameterDirection.Input;
                ID.Value = instance.ID;
                SqlParameter PackName = new SqlParameter("@PackName", SqlDbType.NVarChar, 50);
                PackName.Direction = ParameterDirection.Input;
                PackName.Value = instance.Packname;
                SqlParameter Remark = new SqlParameter("@Remark", SqlDbType.NVarChar, 50);
                Remark.Direction = ParameterDirection.Input;
                Remark.Value = instance.Remark;
                SqlParameter AddUser = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
                AddUser.Direction = ParameterDirection.Input;
                AddUser.Value = instance.AddUser;
                SqlParameter AddTime = new SqlParameter("@AddTime", SqlDbType.DateTime, 50);
                AddTime.Direction = ParameterDirection.Input;
                AddTime.Value = instance.Addtime;
                SqlParameter AllMoney = new SqlParameter("@AllMoney", SqlDbType.Decimal, 50);
                AllMoney.Direction = ParameterDirection.Input;
                AllMoney.Value = instance.AllMoney;
                SqlParameter AllRebate = new SqlParameter("@AllRebate", SqlDbType.Decimal, 50);
                AllRebate.Direction = ParameterDirection.Input;
                AllRebate.Value = instance.AllRebate;
                SqlParameter ProduectList = new SqlParameter("@ProduectList", SqlDbType.NVarChar, 80000);
                ProduectList.Direction = ParameterDirection.Input;
                ProduectList.Value = instance.ProduectList;
                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;

                SqlParameter Type = new SqlParameter("@Type", SqlDbType.NVarChar, 50);
                Type.Direction = ParameterDirection.Input;

                string strFlag = this.GetStringFromQueryString("type", "");
                if (strFlag == "2") //修改
                {
                    Type.Value = 1;
                }
                else
                {
                    Type.Value = 0;
                }
                _Parameters = new IDataParameter[] { ID, PackName, Remark, AddUser, AddTime, AllMoney, AllRebate, ProduectList, Type, ReturnValue };
                string strSql = db.RunProcedureReturnString("sp_AddCrmProductPack", _Parameters, out iResult);
                if (strSql == "1")
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write("0");
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 保存发票代码
        /// </summary>
        private void InsertCrmInvoiceCode()
        {
            int iResult = 0;
            IDataParameter[] _Parameters = new IDataParameter[] { };
            DbSql db = new DbSql();
            try
            {
                string strInvoiceCode = this.GetStringFromQueryString("code", "");
                string strInvoiceType = this.GetStringFromQueryString("type", "");
                string strInvoiceStartCode = this.GetStringFromQueryString("startCode", "");
                string strInvoiceEndCode = this.GetStringFromQueryString("endCode", "");
                string strAddUser = this.UserId.ToString();
                SqlParameter InvoiceCode = new SqlParameter("@InvoiceCode", SqlDbType.NVarChar, 50);
                InvoiceCode.Direction = ParameterDirection.Input;
                InvoiceCode.Value = strInvoiceCode;
                SqlParameter InvoiceType = new SqlParameter("@InvoiceType", SqlDbType.UniqueIdentifier, 50);
                InvoiceType.Direction = ParameterDirection.Input;
                InvoiceType.Value = new Guid(strInvoiceType);
                SqlParameter InvoiceStartCode = new SqlParameter("@InvoiceStartCode", SqlDbType.Int, 10);
                InvoiceStartCode.Direction = ParameterDirection.Input;
                InvoiceStartCode.Value = strInvoiceStartCode;
                SqlParameter InvoiceEndCode = new SqlParameter("@InvoiceEndCode", SqlDbType.Int, 10);
                InvoiceEndCode.Direction = ParameterDirection.Input;
                InvoiceEndCode.Value = strInvoiceEndCode;
                SqlParameter AddUser = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
                AddUser.Direction = ParameterDirection.Input;
                AddUser.Value = new Guid(strAddUser);
                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;

                _Parameters = new IDataParameter[] { InvoiceCode, InvoiceType, InvoiceStartCode, InvoiceEndCode, AddUser, ReturnValue };
                string strSql = db.RunProcedureReturnString("sp_AddCrmInvoiceCode", _Parameters, out iResult);
                if (strSql == "1")
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write(strSql);
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 保存科目
        /// </summary>
        private void InsertCrmSubjectManager(string strJson)
        {
            int iResult = 0;
            IDataParameter[] _Parameters = new IDataParameter[] { };
            DbSql db = new DbSql();
            try
            {
                CrmSubjectManager instance = (CrmSubjectManager)Globals.JSonToObject<CrmSubjectManager>(strJson);
                Globals.SetPropertyValue(instance, "AddUser", this.UserId);
                Globals.SetPropertyValue(instance, "AddTime", System.DateTime.Now);
                SqlParameter SubjectName = new SqlParameter("@SubjectName", SqlDbType.NVarChar, 50);
                SubjectName.Direction = ParameterDirection.Input;
                SubjectName.Value = instance.SubjectName;
                SqlParameter SuperiorSubjectID = new SqlParameter("@SuperiorSubjectID", SqlDbType.UniqueIdentifier, 50);
                SuperiorSubjectID.Direction = ParameterDirection.Input;
                SuperiorSubjectID.Value = instance.SuperiorSubjectID;
                SqlParameter SubjectState = new SqlParameter("@SubjectState", SqlDbType.UniqueIdentifier, 50);
                SubjectState.Direction = ParameterDirection.Input;
                SubjectState.Value = instance.SubjectState;
                SqlParameter SpecificationRemark = new SqlParameter("@SpecificationRemark", SqlDbType.NVarChar, 300);
                SpecificationRemark.Direction = ParameterDirection.Input;
                SpecificationRemark.Value = instance.SpecificationRemark;
                SqlParameter Remark = new SqlParameter("@Remark", SqlDbType.NVarChar, 300);
                Remark.Direction = ParameterDirection.Input;
                Remark.Value = instance.Remark;
                SqlParameter AddUser = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
                AddUser.Direction = ParameterDirection.Input;
                AddUser.Value = instance.AddUser;
                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;

                _Parameters = new IDataParameter[] { SubjectName, SuperiorSubjectID, SpecificationRemark, Remark, AddUser, ReturnValue };
                string strSql = db.RunProcedureReturnString("sp_AddCrmSubjectManager", _Parameters, out iResult);
                if (strSql == "1")
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write(strSql);
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 发票申请保存数据
        /// </summary>
        /// <param name="strJson"></param>
        private void InsertCrmInvoiceApply(string strJson)
        {
            int iResult = 0;
            IDataParameter[] _Parameters = new IDataParameter[] { };
            DbSql db = new DbSql();
            try
            {
                CrmInvoiceApply instance = (CrmInvoiceApply)Globals.JSonToObject<CrmInvoiceApply>(strJson);
                Globals.SetPropertyValue(instance, "AddUser", this.UserId);
                Globals.SetPropertyValue(instance, "AddTime", System.DateTime.Now);
                Globals.SetPropertyValue(instance, "ModifyUser", this.UserId);
                Globals.SetPropertyValue(instance, "ModifyTime", System.DateTime.Now);
                SqlParameter ID = new SqlParameter("@ID", SqlDbType.UniqueIdentifier, 50);
                ID.Direction = ParameterDirection.Input;
                ID.Value = instance.ID;
                SqlParameter OrderId = new SqlParameter("@OrderId", SqlDbType.UniqueIdentifier, 50);
                OrderId.Direction = ParameterDirection.Input;
                OrderId.Value = instance.OrderId;
                SqlParameter InvoiceApplyType = new SqlParameter("@InvoiceApplyType", SqlDbType.UniqueIdentifier, 50);
                InvoiceApplyType.Direction = ParameterDirection.Input;
                InvoiceApplyType.Value = instance.InvoiceApplyType;
                SqlParameter ApplyType = new SqlParameter("@ApplyType", SqlDbType.UniqueIdentifier, 50);
                ApplyType.Direction = ParameterDirection.Input;
                ApplyType.Value = instance.ApplyType;
                SqlParameter InvoiceType = new SqlParameter("@InvoiceType", SqlDbType.UniqueIdentifier, 50);
                InvoiceType.Direction = ParameterDirection.Input;
                InvoiceType.Value = instance.InvoiceType;
                SqlParameter CostMethod = new SqlParameter("@CostMethod", SqlDbType.UniqueIdentifier, 50);
                CostMethod.Direction = ParameterDirection.Input;
                CostMethod.Value = instance.CostMethod;
                SqlParameter CostUser = new SqlParameter("@CostUser", SqlDbType.NVarChar, 50);
                CostUser.Direction = ParameterDirection.Input;
                CostUser.Value = instance.CostUser;
                SqlParameter Identifier = new SqlParameter("@Identifier", SqlDbType.NVarChar, 50);
                Identifier.Direction = ParameterDirection.Input;
                Identifier.Value = instance.Identifier;
                SqlParameter BillingMoney = new SqlParameter("@BillingMoney", SqlDbType.Decimal, 20);
                BillingMoney.Direction = ParameterDirection.Input;
                BillingMoney.Value = instance.BillingMoney;
                SqlParameter ApplyBank = new SqlParameter("@ApplyBank", SqlDbType.NVarChar, 50);
                ApplyBank.Direction = ParameterDirection.Input;
                ApplyBank.Value = instance.ApplyBank;
                SqlParameter ApplyAccount = new SqlParameter("@ApplyAccount", SqlDbType.NVarChar, 50);
                ApplyAccount.Direction = ParameterDirection.Input;
                ApplyAccount.Value = instance.ApplyAccount;
                SqlParameter Addressee = new SqlParameter("@Addressee", SqlDbType.NVarChar, 50);
                Addressee.Direction = ParameterDirection.Input;
                Addressee.Value = instance.Addressee;
                SqlParameter Contact = new SqlParameter("@Contact", SqlDbType.NVarChar, 50);
                Contact.Direction = ParameterDirection.Input;
                Contact.Value = instance.Contact;
                SqlParameter MailingAddress = new SqlParameter("@MailingAddress", SqlDbType.NVarChar, 150);
                MailingAddress.Direction = ParameterDirection.Input;
                MailingAddress.Value = instance.MailingAddress;
                SqlParameter Explain = new SqlParameter("@Explain", SqlDbType.NVarChar, 300);
                Explain.Direction = ParameterDirection.Input;
                Explain.Value = instance.Explain;
                SqlParameter AddUser = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
                AddUser.Direction = ParameterDirection.Input;
                AddUser.Value = instance.AddUser;
                SqlParameter ApplyProductList = new SqlParameter("@ApplyProductList", SqlDbType.NVarChar, 80000);
                ApplyProductList.Direction = ParameterDirection.Input;
                ApplyProductList.Value = instance.ApplyProductList;
                SqlParameter Type = new SqlParameter("@Type", SqlDbType.Int, 2);
                Type.Direction = ParameterDirection.Input;
                Type.Value = int.Parse(this.GetStringFromQueryString("type", "").ToString());

                SqlParameter WorkFlowId = new SqlParameter("@WorkFlowId", SqlDbType.NVarChar, 50);
                WorkFlowId.Direction = ParameterDirection.Input;
                WorkFlowId.Value = instance.WorkFlowId;
                SqlParameter WorkTaskId = new SqlParameter("@WorkTaskId", SqlDbType.NVarChar, 50);
                WorkTaskId.Direction = ParameterDirection.Input;
                WorkTaskId.Value = instance.WorkTaskId;
                SqlParameter WorkFlowInsId = new SqlParameter("@WorkFlowInsId", SqlDbType.NVarChar, 50);
                WorkFlowInsId.Direction = ParameterDirection.Input;
                WorkFlowInsId.Value = instance.WorkFlowInsId;
                SqlParameter WorkTaskInsId = new SqlParameter("@WorkTaskInsId", SqlDbType.NVarChar, 50);
                WorkTaskInsId.Direction = ParameterDirection.Input;
                WorkTaskInsId.Value = instance.WorkTaskInsId;

                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;
                _Parameters = new IDataParameter[] { ID, OrderId, InvoiceApplyType, ApplyType, InvoiceType, CostMethod, 
                                                        CostUser, Identifier, BillingMoney, ApplyBank, ApplyAccount,
                                                        Addressee, Contact, MailingAddress,Explain, AddUser,
                                                        Type, ApplyProductList, WorkFlowId, WorkTaskId, WorkFlowInsId,WorkTaskInsId, ReturnValue};
                string strSql = db.RunProcedureReturnString("sp_AddCrmInvoiceApply", _Parameters, out iResult);
                if (strSql == "1")
                {
                    string userId = this.User.LoginName;
                    string strType = this.GetStringFromQueryString("type", "").ToString();
                    if (strType != "3") //修改
                    {
                        string msg1 = workFlowServiceClient.Start(userId, WorkFlowId.Value.ToString(), WorkTaskId.Value.ToString(),
                             WorkFlowInsId.Value.ToString(), WorkTaskInsId.Value.ToString(), workFlowServiceClient.GetWorkFlowNO(), "提交", "3", this.User.UName + "-发票申请-" + DateTime.Now.ToString(), false);
                    }
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write(strSql);
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 保存渠道客户
        /// </summary>
        /// <param name="strJson"></param>
        private void InsertCrmCustomerChannel(string strJson)
        {
            try
            {
                int iResult = 0;
                IDataParameter[] _Parameters = new IDataParameter[] { };
                DbSql db = new DbSql();

                CrmCustomerChannel instance = (CrmCustomerChannel)Globals.JSonToObject<CrmCustomerChannel>(strJson);
                Globals.SetPropertyValue(instance, "AddUser", this.UserId);
                Globals.SetPropertyValue(instance, "AddTime", System.DateTime.Now);

                SqlParameter ID = new SqlParameter("@ID", SqlDbType.UniqueIdentifier, 50);
                ID.Direction = ParameterDirection.Input;
                ID.Value = instance.ID;
                SqlParameter Code = new SqlParameter("@Code", SqlDbType.Char, 15);
                Code.Direction = ParameterDirection.Input;
                Code.Value = instance.Code;
                SqlParameter CustomerName = new SqlParameter("@CustomerName", SqlDbType.NVarChar, 50);
                CustomerName.Direction = ParameterDirection.Input;
                CustomerName.Value = instance.CustomerName;
                SqlParameter Address = new SqlParameter("@Address", SqlDbType.NVarChar, 50);
                Address.Direction = ParameterDirection.Input;
                Address.Value = instance.Address;
                SqlParameter State = new SqlParameter("@State", SqlDbType.NVarChar, 50);
                State.Direction = ParameterDirection.Input;
                State.Value = instance.State;
                SqlParameter Province = new SqlParameter("@Province", SqlDbType.NVarChar, 50);
                Province.Direction = ParameterDirection.Input;
                Province.Value = instance.Province;
                SqlParameter City = new SqlParameter("@City", SqlDbType.NVarChar, 50);
                City.Direction = ParameterDirection.Input;
                City.Value = instance.City;
                SqlParameter Area = new SqlParameter("@Area", SqlDbType.NVarChar, 50);
                Area.Direction = ParameterDirection.Input;
                Area.Value = instance.Area;
                SqlParameter Decisionmaker = new SqlParameter("@Decisionmaker", SqlDbType.NVarChar, 50);
                Decisionmaker.Direction = ParameterDirection.Input;
                Decisionmaker.Value = instance.Decisionmaker;
                SqlParameter DecisionTel = new SqlParameter("@DecisionTel", SqlDbType.NVarChar, 50);
                DecisionTel.Direction = ParameterDirection.Input;
                DecisionTel.Value = instance.DecisionTel;
                SqlParameter DecisionTel2 = new SqlParameter("@DecisionTel2", SqlDbType.NVarChar, 50);
                DecisionTel2.Direction = ParameterDirection.Input;
                DecisionTel2.Value = instance.DecisionTel2;
                SqlParameter DecisionPosition = new SqlParameter("@DecisionPosition", SqlDbType.NVarChar, 50);
                DecisionPosition.Direction = ParameterDirection.Input;
                DecisionPosition.Value = instance.DecisionPosition;
                SqlParameter DecisionSex = new SqlParameter("@DecisionSex", SqlDbType.Char, 1);
                DecisionSex.Direction = ParameterDirection.Input;
                DecisionSex.Value = instance.DecisionSex;
                SqlParameter CompanyProduct = new SqlParameter("@CompanyProduct", SqlDbType.NVarChar, 100);
                CompanyProduct.Direction = ParameterDirection.Input;
                CompanyProduct.Value = instance.CompanyProduct;
                SqlParameter Tel1 = new SqlParameter("@Tel1", SqlDbType.NVarChar, 50);
                Tel1.Direction = ParameterDirection.Input;
                Tel1.Value = instance.Tel1;
                SqlParameter Tel2 = new SqlParameter("@Tel2", SqlDbType.NVarChar, 50);
                Tel2.Direction = ParameterDirection.Input;
                Tel2.Value = instance.Tel2;
                SqlParameter PersonId = new SqlParameter("@PersonId", SqlDbType.UniqueIdentifier, 50);
                PersonId.Direction = ParameterDirection.Input;
                PersonId.Value = instance.PersonId;
                SqlParameter AreaId = new SqlParameter("@AreaId", SqlDbType.UniqueIdentifier, 50);
                AreaId.Direction = ParameterDirection.Input;
                AreaId.Value = instance.AreaId;
                SqlParameter TypeId = new SqlParameter("@TypeId", SqlDbType.UniqueIdentifier, 50);
                TypeId.Direction = ParameterDirection.Input;
                TypeId.Value = instance.TypeId;
                SqlParameter TradeId = new SqlParameter("@TradeId", SqlDbType.UniqueIdentifier, 50);
                TradeId.Direction = ParameterDirection.Input;
                TradeId.Value = instance.TradeId;
                SqlParameter ProductId = new SqlParameter("@ProductId", SqlDbType.UniqueIdentifier, 50);
                ProductId.Direction = ParameterDirection.Input;
                ProductId.Value = instance.ProductId;
                SqlParameter OriginId = new SqlParameter("@OriginId", SqlDbType.UniqueIdentifier, 50);
                OriginId.Direction = ParameterDirection.Input;
                OriginId.Value = instance.OriginId;
                SqlParameter PropertyId = new SqlParameter("@PropertyId", SqlDbType.UniqueIdentifier, 50);
                PropertyId.Direction = ParameterDirection.Input;
                PropertyId.Value = instance.PropertyId;
                SqlParameter LevelId = new SqlParameter("@LevelId", SqlDbType.UniqueIdentifier, 50);
                LevelId.Direction = ParameterDirection.Input;
                LevelId.Value = instance.LevelId;
                SqlParameter ManagerQuestion = new SqlParameter("@ManagerQuestion", SqlDbType.NVarChar, 500);
                ManagerQuestion.Direction = ParameterDirection.Input;
                ManagerQuestion.Value = instance.ManagerQuestion;
                SqlParameter StrongPoint = new SqlParameter("@StrongPoint", SqlDbType.NVarChar, 200);
                StrongPoint.Direction = ParameterDirection.Input;
                StrongPoint.Value = instance.StrongPoint;
                SqlParameter Explain = new SqlParameter("@Explain", SqlDbType.NVarChar, 500);
                Explain.Direction = ParameterDirection.Input;
                Explain.Value = instance.Explain;
                SqlParameter IsHistory = new SqlParameter("@IsHistory", SqlDbType.Char, 1);
                IsHistory.Direction = ParameterDirection.Input;
                IsHistory.Value = instance.IsHistory;
                SqlParameter IsValue = new SqlParameter("@IsValue", SqlDbType.Int, 2);
                IsValue.Direction = ParameterDirection.Input;
                IsValue.Value = instance.IsValue;
                SqlParameter AddUser = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
                AddUser.Direction = ParameterDirection.Input;
                AddUser.Value = instance.AddUser;

                SqlParameter WorkFlowId = new SqlParameter("@WorkFlowId", SqlDbType.NVarChar, 50);
                WorkFlowId.Direction = ParameterDirection.Input;
                WorkFlowId.Value = instance.WorkFlowId;
                SqlParameter WorkTaskId = new SqlParameter("@WorkTaskId", SqlDbType.NVarChar, 50);
                WorkTaskId.Direction = ParameterDirection.Input;
                WorkTaskId.Value = instance.WorkTaskId;
                SqlParameter WorkFlowInsId = new SqlParameter("@WorkFlowInsId", SqlDbType.NVarChar, 50);
                WorkFlowInsId.Direction = ParameterDirection.Input;
                WorkFlowInsId.Value = instance.WorkFlowInsId;
                SqlParameter WorkTaskInsId = new SqlParameter("@WorkTaskInsId", SqlDbType.NVarChar, 50);
                WorkTaskInsId.Direction = ParameterDirection.Input;
                WorkTaskInsId.Value = instance.WorkTaskInsId;

                string strType = this.GetStringFromQueryString("t", "");
                SqlParameter SaveType = new SqlParameter("@SaveType", SqlDbType.Int, 1);
                SaveType.Direction = ParameterDirection.Input;
                SaveType.Value = int.Parse(strType);

                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;
                _Parameters = new IDataParameter[] { ID,
                                                    Code,
				                                    CustomerName,
				                                    Address,
				                                    State,
				                                    Province,
				                                    City,
				                                    Area,
				                                    Decisionmaker,
				                                    DecisionTel,
				                                    DecisionTel2,
				                                    DecisionPosition,
				                                    DecisionSex,
				                                    CompanyProduct,
				                                    Tel1,
				                                    Tel2,
				                                    PersonId,
				                                    AreaId,
				                                    TypeId,
				                                    TradeId,
				                                    ProductId,
				                                    OriginId,
				                                    PropertyId,
				                                    LevelId,
				                                    ManagerQuestion,
				                                    StrongPoint,
				                                    Explain,
				                                    IsHistory,
				                                    IsValue,
                                                    AddUser,
                                                    WorkFlowId, 
                                                    WorkTaskId, 
                                                    WorkFlowInsId, 
                                                    WorkTaskInsId, 
                                                    SaveType,
                                                    ReturnValue };
                
                string strReturnValue = db.RunProcedureReturnString("sp_SaveCrmCustomerChannel", _Parameters, out iResult);
                if (strReturnValue == "1")
                {
                    if (strType == "5")  //按钮修改
                    {
                        HttpContext.Current.Response.Write("1");
                    }
                    else
                    {
                        string userId = this.User.LoginName;
                        string msg1 = workFlowServiceClient.Start(userId, WorkFlowId.Value.ToString(), WorkTaskId.Value.ToString(),
                             WorkFlowInsId.Value.ToString(), WorkTaskInsId.Value.ToString(), workFlowServiceClient.GetWorkFlowNO(), "提交", "3", "渠道客户-" + CustomerName.Value + "-[" + DateTime.Now.ToString() + "]", false);
                        HttpContext.Current.Response.Write("1");
                    }
                }
                else
                {
                    HttpContext.Current.Response.Write(strReturnValue);
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
        /// <summary>
        /// 保存期初数据
        /// </summary>
        /// <param name="strJson"></param>
        private void InsertCrmLayoutRecord(string strJson)
        {
            try
            {
                int iResult = 0;
                IDataParameter[] _Parameters = new IDataParameter[] { };
                DbSql db = new DbSql();

                CrmLayoutRecord instance = (CrmLayoutRecord)Globals.JSonToObject<CrmLayoutRecord>(strJson);
                Globals.SetPropertyValue(instance, "AddUser", this.UserId);
                Globals.SetPropertyValue(instance, "AddTime", System.DateTime.Now);

                SqlParameter ID = new SqlParameter("@ID", SqlDbType.UniqueIdentifier, 50);
                ID.Direction = ParameterDirection.Input;
                ID.Value = instance.ID;
                SqlParameter CustomerId = new SqlParameter("@CustomerId", SqlDbType.UniqueIdentifier, 50);
                CustomerId.Direction = ParameterDirection.Input;
                CustomerId.Value = instance.CustomerId;
                SqlParameter State = new SqlParameter("@State", SqlDbType.UniqueIdentifier, 50);
                State.Direction = ParameterDirection.Input;
                State.Value = instance.State;
                SqlParameter TotalMoney = new SqlParameter("@TotalMoney", SqlDbType.Decimal, 50);
                TotalMoney.Direction = ParameterDirection.Input;
                TotalMoney.Value = instance.TotalMoney;
                SqlParameter TotalNoPayCount = new SqlParameter("@TotalNoPayCount", SqlDbType.Decimal, 50);
                TotalNoPayCount.Direction = ParameterDirection.Input;
                TotalNoPayCount.Value = instance.TotalNoPayCount;
                SqlParameter TotalPayMoney = new SqlParameter("@TotalPayMoney", SqlDbType.Decimal, 50);
                TotalPayMoney.Direction = ParameterDirection.Input;
                TotalPayMoney.Value = instance.TotalPayMoney;
                SqlParameter ListData = new SqlParameter("@ListData", SqlDbType.NVarChar, 10000);
                ListData.Direction = ParameterDirection.Input;
                ListData.Value = instance.ListData;
                SqlParameter AddUser = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
                AddUser.Direction = ParameterDirection.Input;
                AddUser.Value = instance.AddUser;

                SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
                ReturnValue.Direction = ParameterDirection.Output;

                _Parameters = new IDataParameter[] { ID, CustomerId, State, TotalMoney, TotalNoPayCount, TotalPayMoney, ListData, AddUser, ReturnValue };
                string strSql = db.RunProcedureReturnString("sp_EditCrmLayoutRecord", _Parameters, out iResult);
                if (strSql == "1")
                {
                    HttpContext.Current.Response.Write("1");
                }
                else
                {
                    HttpContext.Current.Response.Write(strSql);
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex);
            }
        }
    }
}